forked from Clueless-Community/fintech-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
2345 lines (2137 loc) · 82.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from fastapi import FastAPI, HTTPException, status
from helpers import functions
app = FastAPI(
title="FinTech API",
description="An API that helps you to deal with your financial calculations.",
version="1",
contact={
"name": "Clueless Community",
"url": "https://www.clueless.tech/",
"email": "https://www.clueless.tech/contact-us",
},
license_info={
"name": " MIT license",
"url": "https://github.com/Clueless-Community/fintech-api/blob/main/LICENSE.md",
},
)
@app.get("/")
def index():
return {
"title": "FinTech API",
"description": "An API that helps you to deal with your financial calculations.",
"version": "1",
"contact": {
"name": "Clueless Community",
"url": "https://www.clueless.tech/",
"email": "https://www.clueless.tech/contact-us",
},
"license_info": {
"name": " MIT license",
"url": "https://github.com/Clueless-Community/fintech-api/blob/main/LICENSE.md",
},
"endpoints": {'/simple_interest_rate': 'Calculate simple interest rates', '/future_sip': 'Calculate Future Value of SIP', '/calculate_pension': 'Calculate pension', '/payback_period': 'Calculate payback period', '/compound_interest': 'Calculate compound interest amount', '/certificate_of_deposit': 'Calculate certificate of deposit (CD)', '/inflation': 'Calculate Inflated amount', '/effective_annual_rate': 'Calculate Effective Annual Rate', '/roi': 'Calculate return on investment', '/compounded_annual_growth_rate': 'Calculate compounded annual growth rate', '/jensens_alpha': "Calculate Jensen's Alpha of a market return", '/wacc': 'Calculate Weighted Average Cost of Capital (WACC)', '/loan_emi': 'Calculate Loan EMI', '/asset_portfolio': 'Calculate Variance of a Two Asset Portfolio', '/put_call_parity': 'Calculate Future Price in Pull-Call Parity', '/bep': 'Calculate Break Even Point', '/fcff': 'Calculate Free Cash Flow to Firm', '/price_to_earning_ratio': 'Calculate price to earning ratio', '/dividend_yield_ratio': 'Calculate dividend yield ratio', '/dividend_payout_ratio': 'Calculate dividend payout ratio', '/debt_to_income_ratio': 'Calculate debt to income ratio per month', '/fixed_charges_coverage_ratio': 'Calculate fixed charges coverage ratio', '/inventory_shrinkage_rate': 'Calculate inventory shrinkage rate', '/markup_percentage': 'Calculate markup percentage', '/sharpe_ratio': 'Calculate sharpe ratio', '/purchasing_power': 'Calculate Purchasing Power', '/monthly_emi': 'Monthly EMI', '/doubling_time': 'Doubling Time', '/weighted_average': 'Weighted Average', '/capital_Asset_Pricing_Model': 'Calculating Capital Asset Pricing Model', '/cost_of_equity': 'Calculate cost of equity', '/cogs': 'Calculate Cost of Goods Sold', '/ruleof72': 'Calculate Rule of 72', '/acid_test_ratio': 'Calculate Acid test ratio', '/inflation_adjusted_return': 'Calculate Inflation Adjusted Return', '/cogr': 'Calculate Compound Annual Growth Rate', '/current_liability_coverage_ratio': 'Calculating current liability coverage ratio', '/levered_beta': 'Levered Beta', '/monthly_payment': 'Monthly payment', '/convexity_duration': 'Convexity Adjusted Duration', '/current_ratio': 'Current Ratio', '/inventory_turnover_ratio': 'Inventory Turnover Ratio', '/inflation_rate': 'Inflation Rate', '/herfindal_Index': 'Calculating herfindal Index', '/discount_opex': 'Discount OPEX', '/project_efficiency': 'Project Efficiency', '/real_gdp': 'Real GDP', '/excess_reserves': 'Excess Reserves', '/discounted_cash_flow': 'Discounted cash flow', '/gdp_growth_rate': 'GDP Growth Rate', '/credit_card_equation': 'Credit Card Equation', '/credit_card_payoff': 'Credit Card Payoff using Debt Avalanche method', '/future_value_of_ordinary_due': 'Calculating future value of ordinary annuity', '/future_value_of_annuity_due': 'Calculating future value of annuity due', '/present_value_of_annuity_due': 'Calculating present value of annuity due', '/compound_annual_growth_rate': 'Calculating compound annual growth rate', '/loan_to_value': 'Calculating loan to value ratio', '/retention_ratio': 'Calculating retention ratio', '/tax_equivalent_yield': 'Calculating tax equivalent yield', '/year_to_year': 'Calculating Year to Year Growth', '/future_value_of_annuity': 'Calculating future worth of annuity', '/balloon_balance': 'Calculating Balloon Balance of a Loan', '/periodic_lease_payment': 'Calculating Periodic lease payment', '/weighted_average_of_values': 'Calculating weighted average', '/discounted_payback_period': 'Calculating discounted payback period', '/yield_to_maturity': 'Calculating Yield to Maturity', '/perpetuity_payment': 'Calculating perpetuity payment', '/zero_coupoun_bond_value': 'Calculating zero coupoun bond value', '/zero_coupoun_bond_yield': 'Calculating Zero Coupon Bond Effective Yield', '/profitability_index': 'Calculating profitability index', '/profitability_index2': 'Calculating profitability index using annual cash flows', '/receivables_turnover_ratio': 'Calculating receivables turnover ratio', '/remaining_balance': 'Calculating remaining balance', '/net_present_value': 'Calculating net present value', '/leverage_ratio_income': 'Calculate Leverage Ratio', '/leverage_ratio_equity': 'Calculate Leverage Ratio', '/time_period_required_for_growth': 'Calculating the time period required for exponential growth', '/preferred-stock-value': 'Calculating the preferred stock value', '/asset_turnover_ratio': 'Calculate asset turnover ratio', '/bid-ask-spread': 'Calculating the Bid Ask Spread', '/calculate-period-FV-PV-rate': 'Calculating No of Periods(Time in years) with respect to Present value(PV) and Future value(FV)', '/balloon-loan-payment': 'Calculating the payments on a loan that has a balance remaining after all periodic payments are mad using balloon laon payment formula', '/monthly_lease_payment': 'Calculating Monthly lease payment', '/401k': 'Calculating an estimate of the 401(k) balance at retirement', '/roth-ira': 'This calculator estimates the balances of Roth IRA savings and regular taxable savings.', '/mortgage-amortization': 'Calculating annual or monthly amortization schedule for a mortgage loan.', '/fha-loan': '', '/enterprise-value': 'Calculating Enterprise Value for a publicly listed company.', '/salary-calculate': 'Converts salary amounts to their corresponding values based on payment frequency.', '/personal_loan': 'Calculate personal loan', '/lumpsum': '', '/refinance': 'Calculate refinance', '/commission_calc': 'compute any one of the following, given inputs for the remaining two: sales price, commission rate, or commission.', '/college_cost': 'calculate total college fee of one year assuming full tuition fee is being paid.', '/diluted-earnings-per-share': 'Calculate Diluted Earnings Per Share (EPS).'}
}
# Endpoints to calculate simple interest.
@app.get(
"/simple_interest_rate",
tags=["simple_interest_rate"],
description="Calculate simple interest rates",
)
def simple_interest_rate(amount_paid: float, principle_amount: float, months: int):
try:
rate = functions.simple_interest_rate(amount_paid, principle_amount, months)
return {
"Tag": "Simple Interest Rate",
"Total amount paid": amount_paid,
"Principle amount": principle_amount,
"Interest Paid": amount_paid - principle_amount,
"Interest Rate": f"{rate}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/future_sip",
tags=["future_sip"],
description="Calculate Future Value of SIP",
)
def future_sip(
interval_investment: float, rate_of_return: float, number_of_payments: int
):
try:
value = functions.future_sip(
interval_investment, rate_of_return, number_of_payments
)
return {
"Tag": "Future Value of SIP",
"Investment at every Interval": interval_investment,
"Interest": (rate_of_return / 100) / 12,
"Number of Payments": number_of_payments,
"Future Value": f"{value}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/calculate_pension",
tags=["calculate_pension"],
description="Calculate pension",
)
def calculate_pension(
monthly_investment_amount,
no_of_years,
annuity_rates,
annuity_purchased,
yearly_interest_rates
):
try:
(
total_corpus,
lump_sum_pension,
monthly_pension
) = functions.calculate_pension(
monthly_investment_amount,no_of_years,annuity_rates,annuity_purchased,yearly_interest_rates)
return{
"Tag":"Calculate pension",
"Total Corpus":total_corpus,
"Lump sum pension":lump_sum_pension,
"Monthly pension":monthly_pension
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# endpoint for payback period
@app.get(
"/payback_period",
tags=["payback_period_years"],
description="Calculate payback period",
)
def payback_period(
years_before_recovery: int, unrecovered_cost: float, cash_flow: float
):
try:
period = functions.payback_period(
years_before_recovery, unrecovered_cost, cash_flow
)
return {
"Tag": "Payback period",
"Years before full recovery": years_before_recovery,
"Unrecovered cost at start of the year": unrecovered_cost,
"Cash flow during the year": cash_flow,
"Payback period": f"{period}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoints to calculate Compound Interest.
@app.get(
"/compound_interest",
tags=["compound_interest_amount"],
description="Calculate compound interest amount",
)
def compound_interest(
principal_amount: float, interest_rate: float, years: int, compounding_period: int
):
try:
amount = functions.compound_interest(
principal_amount, interest_rate, years, compounding_period
)
return {
"Tag": "Compound Interest Amount",
"Principle amount": principal_amount,
"Intrest Rate": interest_rate,
"Time in Years": years,
"Compounding Period": compounding_period,
"Amount after interest": f"{amount}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoints to calculate certificate of deposit (CD)
@app.get(
"/certificate_of_deposit",
tags=["certificate_of_deposit"],
description="Calculate certificate of deposit (CD)",
)
def certificate_of_deposit(
principal_amount: float, interest_rate: float, yrs: int, compounding_per_yr: int
):
try:
cd = functions.certificate_of_deposit(
principal_amount, interest_rate, yrs, compounding_per_yr
)
return {
"Tag": "Certificate of Deposit (CD)",
"Principal amount": principal_amount,
"Interest Rate": interest_rate,
"Time in Years": yrs,
"Number of Compounding per Year": compounding_per_yr,
"Certificate of Deposit (CD)": f"{cd}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# EndPoint to calculate Inflation
@app.get("/inflation", tags=["inflated"], description="Calculate Inflated amount")
def inflation(present_amount: float, inflation_rate: float, years: float):
try:
future_amount = functions.inflation(present_amount, inflation_rate, years)
return {
"Tag": "Inflated Amount",
"Present Amount": present_amount,
"Inflation Rate": inflation_rate,
"Time in Years": years,
"Future Amount": f"{future_amount}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to Calculate Effective Annual Rate
@app.get(
"/effective_annual_rate",
tags=["Effective Annual Rate"],
description="Calculate Effective Annual Rate",
)
def inflation(annual_interest_rate: float, compounding_period: int):
try:
Eff_annual_rate = functions.effective_annual_rate(
annual_interest_rate, compounding_period
)
Eff_annual_rate_percentage = Eff_annual_rate * 100
return {
"Tag": "Effective Annual Rate",
"Annual Intrest Rate": annual_interest_rate,
"Compounding Period": compounding_period,
"Effective Annual Rate (in percentage)": f"{Eff_annual_rate_percentage}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/roi", tags=["return_on_investment"], description="Calculate return on investment"
)
def return_on_investment(current_value_of_investment: float, cost_of_investment: float):
try:
roi = functions.return_on_investment(
current_value_of_investment, cost_of_investment
)
return {
"Tag": "Return on Investment",
"Current Value of Investment": current_value_of_investment,
"Cost of Investment": cost_of_investment,
"Return on Investment": f"{roi}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Compounded Annual Growth Rate.
@app.get(
"/compounded_annual_growth_rate",
tags=["compounded_annual_growth_rate"],
description="Calculate compounded annual growth rate",
)
def compounded_annual_growth_rate(
end_investment_value: float, initial_investment_value: float, years: int
):
try:
cagr = functions.compounded_annual_growth_rate(
end_investment_value, initial_investment_value, years
)
return {
"Tag": "Compounded Annual Growth Rate",
"End investment value": end_investment_value,
"Initial investment value": initial_investment_value,
"Years": years,
"Compounded Annual Growth Rate": f"{cagr}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Jensen's Alpha
@app.get(
"/jensens_alpha",
tags=["jensens_alpha"],
description="Calculate Jensen's Alpha of a market return",
)
def jensens_alpha(
return_from_investment: float,
return_of_appropriate_market_index: float,
risk_free_rate: float,
beta: float,
):
try:
alpha = functions.jensens_alpha(
return_from_investment,
return_of_appropriate_market_index,
risk_free_rate,
beta,
)
return {
"Tag": "Jensen's Alpha",
"Total return from investment": return_from_investment,
"Return of appropriate market index": return_of_appropriate_market_index,
"Risk free rate": risk_free_rate,
"Beta of the portfolio investment w.r.t chosen market index": beta,
"Alpha of the return ": f"{alpha}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate WACC
@app.get(
"/wacc",
tags=["wacc"],
description="Calculate Weighted Average Cost of Capital (WACC)",
)
def weighted_average_cost_of_capital(
firm_equity, firm_debt, cost_of_equity, cost_of_debt, corporate_tax_rate
):
try:
wacc = functions.wacc(
firm_equity, firm_debt, cost_of_equity, cost_of_debt, corporate_tax_rate
)
return {
"Tag": "Weighted Average Cost of Capital (WACC)",
"Market value of firm's equity": firm_equity,
"Market value of firm's debt": firm_debt,
"Cost of equity": cost_of_equity,
"Cost of debt": cost_of_debt,
"Corporate tax rate": corporate_tax_rate,
"WACC": f"{wacc}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/loan_emi",
tags=["load_emi"],
description="Calculate Loan EMI",
)
def loan_emi(principle_amount: float, annual_rate: float, months: int):
try:
emi = functions.loan_emi(principle_amount, annual_rate, months)
return {
"Tag": "Loan Emi",
"Principal amount borrowed": principle_amount,
"Annual Rate of interest": annual_rate,
"Total number of monthly payments": months,
"EMI": f"{round(emi,3)}",
"Total Amount Payble": f"{round(emi*months,3)}",
"Interest amount": f"{round(emi*months-principle_amount,3)}",
}
except Exception as e:
print(e)
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Variance of a Two Asset Portfolio
@app.get(
"/asset_portfolio",
tags=["asset_portfolio"],
description="Calculate Variance of a Two Asset Portfolio",
)
def asset_portfolio(
price_A: float,
price_B: float,
return_A: float,
return_B: float,
standard_dev_A: float,
standard_dev_B: float,
correlation: float,
):
try:
weight_A = price_A / (price_A + price_B)
weight_B = price_B / (price_A + price_B)
cov = correlation * standard_dev_A * standard_dev_B
portfolio_variance = (
weight_A * weight_A * standard_dev_A * standard_dev_A
+ weight_B * weight_B * standard_dev_B * standard_dev_B
+ 2 * weight_A * weight_B * cov
)
expected_return = 100 * (weight_A * return_A + weight_B * return_B)
return {
"Tag": "Portfolio Variance",
"Expected Returns": f"{expected_return}%",
"Portfolio Variance": f"{portfolio_variance}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to Calculate Future Price in Put-Call Parity
@app.get(
"/put_call_parity",
tags=["/put_call_parity"],
description="Calculate Future Price in Pull-Call Parity",
)
def put_call_parity(call_price: float, put_price: float, strike_price: float):
try:
future_amount = functions.put_call_parity(call_price, put_price, strike_price)
return {
"Tag": "Pull Call Parity",
"Future Price": f"{future_amount}",
"Call Price": f"{call_price}",
"Put Price": f"{put_price}",
"Strike Price": f"{strike_price}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate break even point
@app.get(
"/bep",
tags=["bep"],
description="Calculate Break Even Point",
)
def break_even_point(fixed_cost: float, selling_price: float, variable_cost: float):
try:
bep = functions.break_even_point(fixed_cost, selling_price, variable_cost)
return {
"Tag": "Break Even Point (BEP)",
"Fixed costs": fixed_cost,
"Selling price per unit": selling_price,
"Variable cost per unit": variable_cost,
"Break Even Point in units": f"{bep[0]}",
"Break Even Point in Rupees": f"{bep[1]}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate free cash flow to firm
@app.get(
"/fcff",
tags=["fcff"],
description="Calculate Free Cash Flow to Firm",
)
def free_cash_flow_to_firm(
sales: float,
operating_cost: float,
depreciation: float,
interest: float,
tax_rate: float,
fcInv: float,
wcInv: float,
):
try:
ebitda = sales - operating_cost
ebit = ebitda - depreciation
ebt = ebit - interest
eat = ebt - ebt * (tax_rate * 0.01)
fcff = functions.free_cash_flow_to_firm(
sales, operating_cost, depreciation, interest, tax_rate, fcInv, wcInv
)
return {
"Tag": "Free Cash Flow to Firm (FCFF)",
"Earnings before interest, taxes, depreciation and amortization": f"{ebitda}",
"Earnings before interest and taxes : ": f"{ebit}",
"Net Income": f"{eat}",
"Free Cash Flow to Firm": f"{fcff}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Price-to-earning ratio
@app.get(
"/price_to_earning_ratio",
tags=["price_to_earning_ratio"],
description="Calculate price to earning ratio",
)
def price_to_earning_ratio(share_price: float, earnings_per_share: float):
try:
p_e_ratio = functions.price_to_earning(share_price, earnings_per_share)
return {
"Tag": "Price to Earning ratio",
"Share price": share_price,
"Earning per share": earnings_per_share,
"Price to Earning ratio": f"{p_e_ratio}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Dividend yield ratio
@app.get(
"/dividend_yield_ratio",
tags=["dividend_yield_ratio"],
description="Calculate dividend yield ratio",
)
def dividend_yield_ratio(dividend_per_share: float, share_price: float):
try:
dividend_yield = functions.dividend_yield_ratio(dividend_per_share, share_price)
return {
"Tag": "Dividend yield ratio",
"Dividend per share": dividend_per_share,
"Share price": share_price,
"Dividend yield ratio": f"{dividend_yield}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Dividend payout ratio
@app.get(
"/dividend_payout_ratio",
tags=["dividend_payout_ratio"],
description="Calculate dividend payout ratio",
)
def dividend_payout_ratio(dividend_per_share: float, earnings_per_share: float):
try:
dividend_payout = functions.dividend_payout_ratio(
dividend_per_share, earnings_per_share
)
return {
"Tag": "Dividend payout ratio",
"Dividend per share": dividend_per_share,
"Share price": earnings_per_share,
"Dividend yield ratio": f"{dividend_payout}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate DTI
@app.get(
"/debt_to_income_ratio",
tags=["debt_to_income_ratio"],
description="Calculate debt to income ratio per month",
)
def debt_to_income_ratio(annual_income: float, total_debt_per_month: float):
try:
DTI = functions.debt_to_income_ratio(annual_income, total_debt_per_month)
return {
"Tag": "Debt to income ratio",
"Annual income": annual_income,
"Total debt per month": total_debt_per_month,
"Debt to income ratio per month": f"{DTI}%",
}
except:
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE)
# Endpoint to calculate fixed charge coverage ratio:
@app.get(
"/fixed_charges_coverage_ratio",
tags=["fixed_charges_coverage_ratio"],
description="Calculate fixed charges coverage ratio",
)
def fixed_charge_coverage_ratio(
earnings_before_interest_taxes: float,
fixed_charge_before_tax: float,
interest: float,
):
try:
fccr = functions.fixed_charge_coverage_ratio(
earnings_before_interest_taxes, fixed_charge_before_tax, interest
)
return {
"Tag": "fixed charges coverage ratio",
"Earnings before interest taxes": earnings_before_interest_taxes,
"Fixed charge before tax": fixed_charge_before_tax,
"Interest": interest,
"Fixed charge coverage ratio": f"{fccr}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Inventory Shrinkage Rate
@app.get(
"/inventory_shrinkage_rate",
tags=["inventory_shrinkage_rate"],
description="Calculate inventory shrinkage rate",
)
def inventory_shrinkage_rate(recorded_inventory: float, actual_inventory: float):
try:
inventory_shrinkage_rate = functions.inventory_shrinkage_rate(
recorded_inventory, actual_inventory
)
return {
"Tag": "Inventory shrinkage rate",
"Recorded Inventory": recorded_inventory,
"Actual Inventory": actual_inventory,
"Inventory Shrinkage Rate": inventory_shrinkage_rate,
"Inventory Shrinkage Rate (%)": inventory_shrinkage_rate * 100,
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Markup Percentage
@app.get(
"/markup_percentage",
tags=["markup_percentage"],
description="Calculate markup percentage",
)
def markup_percentage(price: float, cost: float):
try:
markup_percentage = functions.markup_percentage(price, cost)
return {
"Tag": "Markup Percentage",
"Price": price,
"Cost": cost,
"Markup Percentage": markup_percentage,
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Sharpe ratio
@app.get(
"/sharpe_ratio",
tags=["sharpe_ratio"],
description="Calculate sharpe ratio",
)
def sharpe_ratio(
portfolio_return: float,
risk_free_rate: float,
standard_deviation_of_portfolio: float,
):
try:
sharpe_ratio = functions.sharpe_ratio(
portfolio_return, risk_free_rate, standard_deviation_of_portfolio
)
return {
"Tag": "Sharpe Ratio",
"Portfolio Return": portfolio_return,
"Risk Free Rate": risk_free_rate,
"Standard Deviation of Portfolio": standard_deviation_of_portfolio,
"Sharpe Ratio": f"{sharpe_ratio}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate purchase power
@app.get(
"/purchasing_power",
tags=["purchasing_power"],
description="Calculate Purchasing Power",
)
def purchasing_power(initial_amount: float, annual_inflation_rate: float, time: float):
try:
purchasing_power = functions.purchasing_power(
initial_amount, annual_inflation_rate, time
)
return {
"Tag": "Purchasing Power",
"Initial Amount": initial_amount,
"Annual Inflation Rate": annual_inflation_rate,
"Time in years": time,
"Purchasing Power": f"{purchasing_power}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Monthly EMI
@app.get(
"/monthly_emi",
tags=["monthly_emi"],
description="Monthly EMI",
)
def monthly_emi(loan_amt: float, interest_rate: float, number_of_installments: float):
try:
monthly_emi = functions.monthly_emi(
loan_amt, interest_rate, number_of_installments
)
return {
"Tag": "Monthly EMI",
"Loan Amount": loan_amt,
"Interest Rate": interest_rate,
"Number of Installments": number_of_installments,
"Total EMI": f"{monthly_emi}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate doubling time
@app.get(
"/doubling_time",
tags=["doubling_time"],
description="Doubling Time",
)
def doubling_time(r: float):
try:
doubling_time = functions.doubling_time(r)
return {
"Tag": "Doubling Time",
"Rate of Interest": r,
"Time in years to double the money": f"{doubling_time}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate weighted average
@app.get(
"/weighted_average",
tags=["weighted_average"],
description="Weighted Average",
)
def weighted_average(ratio: list, rates: list):
try:
weighted_average = functions.weighted_average(ratio, rates)
return {
"Tag": "Weighted Average",
"Ratio of each investment principal": ratio,
"Rates": rates,
"Weighted average : ": f"{weighted_average}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate Capital Asset Pricing Model
@app.get(
"/capital_Asset_Pricing_Model",
tags=["capital_Asset_Pricing_Model"],
description="Calculating Capital Asset Pricing Model",
)
def Capital_Asset_Pricing_Model(
risk_free_interest_rate: float,
beta_of_security: float,
expected_market_return: float,
):
try:
Capital_Asset_Pricing_Model = functions.Capital_Asset_Pricing_Model(
risk_free_interest_rate, beta_of_security, expected_market_return
)
return {
"Tag": "Capital Asset Pricing Model",
"Risk free interest rate": risk_free_interest_rate,
"Beta of security": beta_of_security,
"Expected market return": expected_market_return,
"Capital asset expected return": f"{Capital_Asset_Pricing_Model}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate cost of equity
@app.get(
"/cost_of_equity",
tags=["cost_of_equity"],
description="Calculate cost of equity",
)
def cost_of_equity(
risk_free_rate_of_return: float, Beta: float, market_rate_of_return: float
):
try:
costOfEquity = functions.cost_of_equity(
risk_free_rate_of_return, Beta, market_rate_of_return
)
return {
"Tag": "Cost of Equity",
"Risk free rate of return": risk_free_rate_of_return,
"Beta": Beta,
"Market rate of return ": market_rate_of_return,
"Cost of equity": f"{costOfEquity}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate cost of goods sold
@app.get(
"/cogs",
tags=["cogs"],
description="Calculate Cost of Goods Sold",
)
def cost_of_goods_sold(
beginning_inventory: float, purchases: float, ending_inventory: float
):
try:
cogs = functions.cost_of_goods_sold(
beginning_inventory, purchases, ending_inventory
)
return {
"Tag": "Cost of Goods Sold",
"Beginning Inventory": beginning_inventory,
"Purchases during the period": purchases,
"Ending Inventory": ending_inventory,
"Cost of Goods Sold(In Rupees)": f"{cogs}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate rule of 72
@app.get(
"/ruleof72",
tags=["ruleof72"],
description="Calculate Rule of 72",
)
def rule_of_72(rate_of_roi: float):
try:
time_period = functions.rule_of_72(rate_of_roi)
return {
"Tag": "Rule of 72",
"Rate of ROI": rate_of_roi,
"Time period in which investment get double(in years)": f"{time_period}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate acid test ratio
@app.get(
"/acid_test_ratio",
tags=["acid_test_ratio"],
description="Calculate Acid test ratio",
)
def acid_test_ratio(
cash: float,
marketable_securities: float,
accounts_receivable: float,
current_liabilities: float,
):
try:
ratio = functions.acid_test_ratio(
cash, marketable_securities, accounts_receivable, current_liabilities
)
return {
"Tag": "Acid Test Ratio",
"Cash and Cash Equivalents": cash,
"Marketable Securities": marketable_securities,
"Accounts Receivable": accounts_receivable,
"Current Liabilities": current_liabilities,
"Acid Test Ratio (Quick Ratio)": f"{ratio}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate inflation adjusted return
@app.get(
"/inflation_adjusted_return",
tags=["inflation_adjusted_return"],
description="Calculate Inflation Adjusted Return",
)
def inflation_adjusted_return(
beginning_price: float,
ending_price: float,
dividends: float,
beginning_cpi_level: float,
ending_cpi__level: float,
):
try:
stock_return = (ending_price - beginning_price + dividends) / beginning_price
inflation = (ending_cpi__level - beginning_cpi_level) / beginning_cpi_level
inflation_adj_return = functions.inflation_adjusted_return(
beginning_price,
ending_price,
dividends,
beginning_cpi_level,
ending_cpi__level,
)
return {
"Tag": "Inflation Adjusted Return",
"Stock Return": f"{stock_return}%",
"Inflation Rate": f"{inflation}%",
"Inflation Adjusted Return": f"{inflation_adj_return}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate compound annual growth rate
@app.get(
"/cogr",
tags=["cogr"],
description="Calculate Compound Annual Growth Rate",
)
def compound_annual_growth_rate(
beginning_value: float, ending_value: float, years: int
):
try:
rate = functions.compound_annual_growth_rate(
beginning_value, ending_value, years
)
return {
"Tag": "Compound Annual Growth Rate",
"Beginning Value": beginning_value,
"Ending Value": ending_value,
"Compound Annual Growth Rate": f"{rate}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate current liability coverage ratio
@app.get(
"/current_liability_coverage_ratio",
tags=["current_liability_coverage_ratio"],
description="Calculating current liability coverage ratio",
)
def current_liability_coverage_ratio(
net_cash_from_operating_activities: float,
total_current_liabilities: float,
number_of_liabilities: int,
):
try:
current_liability_coverage_ratio = functions.current_liability_coverage_ratio(
net_cash_from_operating_activities,
total_current_liabilities,
number_of_liabilities,
)
return {
"Tag": "current liability coverage ratio",
"net cash from operating activities": net_cash_from_operating_activities,
"total current liabilities": total_current_liabilities,
"number of liabilities": number_of_liabilities,
"current liability coverage ratio": f"{current_liability_coverage_ratio}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/levered_beta",
tags=["levered_beta"],
description="Levered Beta",
)
def levered_beta(unlevered_beta: float, tax_rate: float, debt: float, equity: float):
try:
l_beta = functions.levered_beta(unlevered_beta, tax_rate, debt, equity)
return {
"Tag": "Levered Beta",
"Unlevered Beta": unlevered_beta,
"Tax rate": tax_rate,
"debt": debt,
"Equity": equity,
"Levered Beta": f"{l_beta}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/monthly_payment",
tags=["monthly_payment"],
description="Monthly payment",
)
def monthly_payment(
principal: float,
interest_rate: float,
number_of_periods: float,
payments_per_period: float,
):
try:
monthly_pay = functions.monthly_payment(
principal, interest_rate, number_of_periods, payments_per_period
)
return {
"Tag": "Monthly Payment",
"Principal": principal,
"Interest Rate": interest_rate,
"Number of Periods": number_of_periods,
"Payments per period": payments_per_period,
"Levered Beta": f"{monthly_pay}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
@app.get(
"/convexity_duration",
tags=["convexity_duration"],
description="Convexity Adjusted Duration",
)
def duration(rate, coupon_rate, frequency, face_value, settlement_date, maturity_date):
try:
duration = functions.duration(
rate, coupon_rate, frequency, face_value, settlement_date, maturity_date
)
return {
"Tag": "Convexity Adjusted Duration",
"Market Rate": rate,
"Coupon rate": coupon_rate,
"Frequency": frequency,
"Face Value": face_value,
"Settlement Date": settlement_date,
"Maturity Date": maturity_date,
"Convexity Adjusted Duration": f"{duration}",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Endpoint to calculate current ratio
@app.get(
"/current_ratio",
tags=["current_ratio"],
description="Current Ratio",
)
def current_ratio(total_current_assets: float, total_liabilities: float):
try:
ratio = functions.current_ratio(total_current_assets, total_liabilities)
return {
"Tag": "Current Ratio",
"Total Current Assets": total_current_assets,
"Total Liabilities": total_liabilities,