-
Notifications
You must be signed in to change notification settings - Fork 106
/
main.py
2035 lines (1744 loc) · 68.7 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, Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.responses import JSONResponse
import jwt
# Importing all the tasks
from tasks.simple_interest_rate import simple_interest_rate_task
from tasks.future_sip import future_sip_task
from tasks.calculate_pension import calculate_pension_task
from tasks.payback_period import payback_period_task
from tasks.compound_interest import compound_interest_task
from tasks.certificate_of_deposit import certificate_of_deposit_task
from tasks.inflation import inflation_task
from tasks.roi import return_on_investment_task
from tasks.jensens_alpha import jensens_alpha_task
from tasks.social_securities import ss_task
from tasks.tax_equivalent_yield import tax_equivalent_yield_task
from tasks.time_period_required_for_growth import time_period_required_for_growth_task
from tasks.treynor_ratio import treynor_ratio_task
from tasks.wacc import weighted_average_cost_of_capital_task
from tasks.loan_emi import loan_emi_task
from tasks.asset_portfolio import asset_portfolio_task
from tasks.put_call_parity import put_call_parity_task
from tasks.bep import break_even_point_task
from tasks.fcff import free_cash_flow_to_firm_task
from tasks.price_to_earning_ratio import price_to_earning_ratio_task
from tasks.dividend_yield_ratio import dividend_yield_ratio_task
from tasks.dividend_payout_ratio import dividend_payout_ratio_task
from tasks.debt_to_income_ratio import debt_to_income_ratio_task
from tasks.fixed_charges_coverage_ratio import fixed_charge_coverage_ratio_task
from tasks.inventory_shrinkage_rate import inventory_shrinkage_rate_task
from tasks.markup_percentage import markup_percentage_task
from tasks.sharpe_ratio import sharpe_ratio_task
from tasks.purchasing_power import purchasing_power_task
from tasks.monthly_emi import monthly_emi_task
from tasks.doubling_time import doubling_time_task
from tasks.weighted_average import weighted_average_task
from tasks.capital_Asset_Pricing_Model import Capital_Asset_Pricing_Model_task
from tasks.cost_of_equity import cost_of_equity_task
from tasks.cogs import cost_of_goods_sold_task
from tasks.ruleof72 import rule_of_72_task
from tasks.acid_test_ratio import acid_test_ratio_task
from tasks.inflation_adjusted_return import inflation_adjusted_return_task
from tasks.cogr import compound_annual_growth_rate_task
from tasks.current_liability_coverage_ratio import current_liability_coverage_ratio_task
from tasks.levered_beta import levered_beta_task
from tasks.monthly_payment import monthly_payment_task
from tasks.convexity_duration import duration_task
from tasks.current_ratio import current_ratio_task
from tasks.credit_card_equation import credit_card_equation_task
from tasks.credit_card_payoff import credit_card_payoff_task
from tasks.discount_opex import discount_opex_task
from tasks.discounted_cash_flow import discounted_cash_flow_task
from tasks.effective_annual_rate import effective_annual_rate_task
from tasks.excess_reserves import excess_reserves_task
from tasks.future_value_of_annuity_due import future_value_of_annuity_due_task
from tasks.future_value_of_ordinary_due import future_value_of_ordinary_due_task
from tasks.gdp_growth_rate import gdp_growth_rate_task
from tasks.herfindahl_Index import herfindahl_Index_task
from tasks.inflation_rate import inflation_rate_task
from tasks.inventory_turnover_ratio import inventory_turnover_ratio_task
from tasks.loan_to_value import loan_to_value_task
from tasks.present_value_of_annuity_due import present_value_of_annuity_due_task
from tasks.project_efficiency import project_efficiency_task
from tasks.real_gdp import real_gdp_task
from tasks.weighted_average_of_values import weighted_average_of_values_task
from tasks.year_to_year import year_over_year_task
from tasks.yield_to_maturity import yield_to_maturity_task
from tasks.zero_coupoun_bond_value import zero_coupon_bond_value_task
from tasks.zero_coupoun_bond_yield import zero_coupon_bond_yield_task
from tasks.balloon_balance import balloon_balance_task
from tasks.discounted_payback_period import discounted_payback_period_task
from tasks.future_value_of_annuity import future_value_of_annuity_task
from tasks.leverage_ratio_equity import leverage_equity_task
from tasks.leverage_ratio_income import leverage_income_task
from tasks.net_present_value import net_present_value_task
from tasks.periodic_lease_payment import periodic_lease_payment_task
from tasks.perpetuity_payment import perpetuity_payment_task
from tasks.profitability_index import profitability_index_task
from tasks.profitability_index2 import profitability_index2_task
from tasks.receivables_turnover_ratio import receivables_turnover_ratio_task
from tasks.remaining_balance import remaining_balance_task
from tasks.retention_ratio import retention_ratio_task
from tasks.roi_equity_funds import calculate_roi_equity_funds_task
from tasks.student_loan import student_loan_task
from tasks.commission_calc import commission_calc_task
from tasks.lumpsum import calculate_lumpsum_task
from tasks.personal_loan import personal_loan_task
from tasks.refinance import refinance_task
from tasks.asdcr import asdcr_task
from tasks.calculate_gst import calculate_gst_task
from tasks.calculate_market_cap import calculate_market_cap_task
from tasks.calculate_retirement_goals import calculate_retirement_goals_task
from tasks.college_cost import college_cost_task
from tasks.diluted_earnings_per_share import calculate_diluted_eps_task
from tasks.salary_calculate import salary_calculate_task
from tasks.enterprise_value import calculate_enterprise_value_task
from tasks.fha_loan import fha_loan_task
from tasks.mortgage_amortization import mortgage_amortization_task
from tasks.roth_ira import roth_ira_task
from tasks.k401 import estimate_401k_task
from tasks.monthly_lease_payment import monthly_lease_payment_task
from tasks.calculate_period_FV_PV_rate import CalculatePeriods_task
from tasks.bid_ask_spread import bid_ask_spread_task
from tasks.asset_turnover_ratio import asset_turnover_ratio_task
from tasks.preferred_stock_value import preferred_stock_value_task
from tasks.accounts_payable_turnover_ratio import accounts_payable_turnover_ratio_task
from tasks.accrint import accrued_interest_task
from tasks.balloon_loan_payment import balloon_loan_payment_task
from tasks.calculate_bvps import calculate_bvps_task
from tasks.calculate_expected_return_of_portfolio import calculate_expected_return_of_portfolio_task
from tasks.calculate_financial_leverage import calculate_financial_leverage_task
from tasks.calculate_gratuity import calculate_gratuity_task
from tasks.calculate_macaulay_duration import calculate_macaulay_duration_task
from tasks.calculate_net_profit_margin import calculate_net_profit_margin_task
from tasks.calculate_post_tax_return_percentage import calculate_post_tax_return_percentage_task
from tasks.calculate_salary import calculate_salary_task
from tasks.capital_gains_yield import capital_gains_yield_task
from tasks.capitalization_rate import capitalization_rate_task
from tasks.free_cash_flow_to_equity import free_cash_flow_to_equity_task
from tasks.loan_affordability import calculate_loan_affordability_task
from tasks.bond_equivalent_yield import bond_equivalent_yield_task
from tasks.calculate_vat import calculate_vat_task
from tasks.loan_to_value_ratio import loan_to_value_ratio_task
from tasks.mortrages import mortrage_task
from tasks.net_worth import net_worth_calculation_task
from tasks.personal_savings import personal_savings_task
from tasks.portfolio_return_monte_carlo import portfolio_return_monte_carlo_task
from tasks.calculate_capm import calculate_capm
from tasks.debt_service_coverage_ratio import debt_service_coverage_ratio_task
from tasks.profit_percentage import profit_percentage_task
from tasks.loss_percentage import loss_percentage_task
from tasks.defensive_interval_ratio import defensive_interval_ratio_task
from tasks.RateofReturn import calculate_rate_of_return
from tasks.cash_conversion_cycle import cash_conversion_cycle_task
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PolicyPremium import calculate_policy_premium
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn, SavingGoal, InterestCoverageRatio, MarginOfSafety, TaxBracketCalculator
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PriceElasticity import calculate_price_elasticity
from tasks.average_payment_period import average_payment_period_task
from tasks.Saving_Goal import saving_goal
from tasks.modified_internal_rate_of_return import calculate_modified_internal_rate_of_return_task
from tasks.interest_coverage_ratio import interest_coverage_ratio_task
from tasks.tax_bracket_calculator import tax_bracket_calculator
from tasks.margin_of_safety import margin_of_safety_task
# Creating the app
app = FastAPI(
title="FinTech API",
description="An API that helps you to deal with your financial calculations.",
version="2",
contact={
"name": "Clueless Community",
"url": "https://www.clueless.tech/",
},
license_info={
"name": " MIT license",
"url": "https://github.com/Clueless-Community/fintech-api/blob/main/LICENSE.md",
},
)
# Adding the routes
@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/",
},
"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",
"/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).",
"/asdcr": "Calculate Annual Debt Service Coverage Ratio",
"/portfolio_return_monte_carlo":"Calculates Portfolio returns based on Monte Carlo Simulation",
"/profit_percent": "Calculates the profit percentage",
"/loss_percent": "Calculates the loss percentage",
"/average_payment_period": "Calculate Average Payment Period a metric that allows a business to see how long it takes on average to pay its vendors.",
"/modified_internal_rate_of_return": "Calculate modified internal rate of return",
"/interest_coverage_ratio": "Calculates interest coverage ratio",
"/margin_of_safety": "Calculates margin of safety",
},
}
class UnauthorizedException(HTTPException):
def __init__(self, detail="Unauthorized"):
super().__init__(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=detail,
headers={"WWW-Authenticate": "Bearer"},
)
# Validate access token (Not for all endpoints)
def validate_access_token(credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer())):
try:
token = credentials.credentials
payload = jwt.decode(token,"fintech-api", algorithms=["HS256"])
return payload
except jwt.exceptions.DecodeError:
raise UnauthorizedException()
# Endpoint to generate access token
@app.get("/generate-access-token")
def generate_access_token():
token = jwt.encode({},"fintech-api", algorithm="HS256")
return {"access_token": token}
# Endpoints to calculate simple interest.
@app.post(
"/simple_interest_rate",
tags=["simple_interest_rate"],
description="Calculate simple interest rates",
)
def simple_interest_rate(request: SimpleInterestRateRequest):
return simple_interest_rate_task(request.amount_paid, request.principle_amount, request.months)
# Endpoints to calculate Future sip
@app.post(
"/future_sip",
tags=["future_sip"],
description="Calculate Future Value of SIP",
)
def future_sip(
request: futureSip,
payload: dict = Depends(validate_access_token)
):
return future_sip_task(request.interval_investment, request.rate_of_return, request.number_of_payments)
# Endpoints to calculate Future value
@app.post(
"/calculate_pension",
tags=["calculate_pension"],
description="Calculate pension",
)
def calculate_pension(
request: calculatePension
):
return calculate_pension_task(request.monthly_investment_amount, request.no_of_years, request.annuity_rates, request.annuity_purchased, request.yearly_interest_rates)
# endpoint for payback period
@app.post(
"/payback_period",
tags=["payback_period_years"],
description="Calculate payback period",
)
def payback_period(
request: paybackPeriod,
):
return payback_period_task(request.initial_investment, request.cashflow)
# Endpoints to calculate Compound Interest.
@app.post(
"/compound_interest",
tags=["compound_interest_amount"],
description="Calculate compound interest amount",
)
def compound_interest(
request: compoundInterest
):
return compound_interest_task(request.principal_amount, request.interest_rate, request.years ,request.compounding_period)
# 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
):
return certificate_of_deposit_task(principal_amount, interest_rate, yrs, compounding_per_yr)
# EndPoint to calculate Inflation
@app.get("/inflation", tags=["inflated"], description="Calculate Inflated amount")
def inflation(present_amount: float, inflation_rate: float, years: float):
return inflation_task(present_amount, inflation_rate, years)
# Endpoint to Calculate Effective Annual Rate
@app.get(
"/effective_annual_rate",
tags=["Effective Annual Rate"],
description="Calculate Effective Annual Rate",
)
def effective_annual_rate(annual_interest_rate: float, compounding_period: int):
return effective_annual_rate_task(annual_interest_rate, compounding_period)
@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):
return return_on_investment_task(current_value_of_investment, cost_of_investment)
# 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,
):
return jensens_alpha_task( return_from_investment, return_of_appropriate_market_index, risk_free_rate, beta)
# 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
):
return weighted_average_cost_of_capital_task( firm_equity, firm_debt, cost_of_equity, cost_of_debt, corporate_tax_rate)
@app.get(
"/loan_emi",
tags=["load_emi"],
description="Calculate Loan EMI",
)
def loan_emi(principle_amount: float, annual_rate: float, months: int):
return loan_emi_task(principle_amount, annual_rate, months)
# 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,
):
return asset_portfolio_task(
price_A, price_B, return_A, return_B, standard_dev_A, standard_dev_B, correlation
)
# 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):
return put_call_parity_task(call_price, put_price, strike_price)
# 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):
return break_even_point_task(fixed_cost, selling_price, variable_cost)
# 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,
):
return free_cash_flow_to_firm_task(
sales, operating_cost, depreciation, interest, tax_rate, fcInv, wcInv
)
# 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):
return price_to_earning_ratio_task(share_price, earnings_per_share)
# 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):
return dividend_yield_ratio_task(dividend_per_share, share_price)
# 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):
return dividend_payout_ratio_task(dividend_per_share, earnings_per_share)
# 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):
return debt_to_income_ratio_task(annual_income, total_debt_per_month)
# 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,
):
return fixed_charge_coverage_ratio_task(
earnings_before_interest_taxes, fixed_charge_before_tax, interest
)
# 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):
return inventory_shrinkage_rate_task(recorded_inventory, actual_inventory)
# Endpoint to calculate Markup Percentage
@app.get(
"/markup_percentage",
tags=["markup_percentage"],
description="Calculate markup percentage",
)
def markup_percentage(price: float, cost: float):
return markup_percentage_task(price, cost)
# 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,
):
return sharpe_ratio_task(portfolio_return, risk_free_rate, standard_deviation_of_portfolio)
# 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):
return purchasing_power_task(initial_amount, annual_inflation_rate, time)
# 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):
return monthly_emi_task(loan_amt, interest_rate, number_of_installments)
# Endpoint to calculate doubling time
@app.get(
"/doubling_time",
tags=["doubling_time"],
description="Doubling Time",
)
def doubling_time(r: float):
return doubling_time_task(r)
# Endpoint to calculate weighted average
@app.post(
"/weighted_average",
tags=["weighted_average"],
description="Weighted Average",
)
def weighted_average(ratio: list, rates: list):
return weighted_average_task(ratio, rates)
# 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,
):
return Capital_Asset_Pricing_Model_task(
risk_free_interest_rate, beta_of_security, expected_market_return
)
# 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
):
return cost_of_equity_task(risk_free_rate_of_return, Beta, market_rate_of_return)
# 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
):
return cost_of_goods_sold_task(beginning_inventory, purchases, ending_inventory)
# Endpoint to calculate rule of 72
@app.get(
"/ruleof72",
tags=["ruleof72"],
description="Calculate Rule of 72",
)
def rule_of_72(rate_of_roi: float):
return rule_of_72_task(rate_of_roi)
# 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,
):
return acid_test_ratio_task(
cash, marketable_securities, accounts_receivable, current_liabilities
)
# 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,
):
return inflation_adjusted_return_task(
beginning_price,
ending_price,
dividends,
beginning_cpi_level,
ending_cpi__level,
)
# 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
):
return compound_annual_growth_rate_task(beginning_value, ending_value, years)
# 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,
):
return current_liability_coverage_ratio_task(
net_cash_from_operating_activities, total_current_liabilities, number_of_liabilities
)
@app.get(
"/levered_beta",
tags=["levered_beta"],
description="Levered Beta",
)
def levered_beta(unlevered_beta: float, tax_rate: float, debt: float, equity: float):
return levered_beta_task(unlevered_beta, tax_rate, debt, equity)
@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,
):
return monthly_payment_task(principal, interest_rate, number_of_periods, payments_per_period)
@app.get(
"/convexity_duration",
tags=["convexity_duration"],
description="Convexity Adjusted Duration",
)
def duration(rate, coupon_rate, frequency, face_value, settlement_date, maturity_date):
return duration_task(rate, coupon_rate, frequency, face_value, settlement_date, maturity_date)
# 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):
return current_ratio_task(total_current_assets, total_liabilities)
# Endpoint to calculate inventory turnover ratio
@app.get(
"/inventory_turnover_ratio",
tags=["inventory_turnover_ratio"],
description="Inventory Turnover Ratio",
)
def inventory_turnover_ratio(
cost_of_goods_sold: float, beginning_inventory: float, ending_inventory: float
):
return inventory_turnover_ratio_task(
cost_of_goods_sold, beginning_inventory, ending_inventory
)
# Endpoint to calculate inflation rate
@app.get(
"/inflation_rate",
tags=["inflation_rate"],
description="Inflation Rate",
)
def inflation_rate(bigger_year: int, smaller_year: int, base_year: int):
return inflation_rate_task(bigger_year, smaller_year, base_year)
# Endpoint to calculate Herfindahl index
@app.get(
"/herfindahl_Index",
tags=["herfindahl_Index"],
description="Calculating herfindahl Index",
)
def herfindahl_Index(Firms_market_shares: str):
return herfindahl_Index_task(Firms_market_shares)
@app.get(
"/discount_opex",
tags=["discount_opex"],
description="Discount OPEX",
)
def discount_opex(annual_opex: float, wacc: float, project_lifetime: float):
return discount_opex_task(annual_opex, wacc, project_lifetime)
@app.get(
"/project_efficiency",
tags=["project_efficiency"],
description="Project Efficiency",
)
def project_efficiency(annual_production: float, collector_surface: float, dni: float):
return project_efficiency_task(annual_production, collector_surface, dni)
@app.get(
"/real_gdp",
tags=["real_gdp"],
description="Real GDP",
)
def real_gdp(nominal_gdp: float, gdp_deflator: float):
return real_gdp_task(nominal_gdp, gdp_deflator)
@app.get(
"/excess_reserves",
tags=["excess_reserves"],
description="Excess Reserves",
)
def excess_reserves(deposits: float, reserve_requirement: float):
return excess_reserves_task(deposits, reserve_requirement)
@app.get(
"/discounted_cash_flow",
tags=["discounted_cash_flow"],
description="Discounted cash flow",
)
def discounted_cash_flow(
real_feed_in_tariff: float,
annual_production: float,
wacc: float,
project_lifetime: float,
):
return discounted_cash_flow_task(
real_feed_in_tariff, annual_production, wacc, project_lifetime
)
@app.get(
"/gdp_growth_rate",
tags=["gdp_growth_rate"],
description="GDP Growth Rate",
)
def gdp_growth_rate(current_year_gdp: float, last_year_gdp: float):
return gdp_growth_rate_task(current_year_gdp, last_year_gdp)
@app.get(
"/credit_card_equation",
tags=["credit_card_equation"],
description="Credit Card Equation",
)
def credit_card_equation(
balance: float, monthly_payment: float, daily_interest_rate: float
):
return credit_card_equation_task(balance, monthly_payment, daily_interest_rate)
@app.post(
"/credit_card_payoff",
tags=["credit_card_payoff"],
description="Credit Card Payoff using Debt Avalanche method",
)
def credit_card_payoff(
debts: list, interest_rates: list, minimum_payments: list, monthly_payment: int,
payload: dict = Depends(validate_access_token)
):
return credit_card_payoff_task(
debts, interest_rates, minimum_payments, monthly_payment
)
# Endpoint to calculate future value of the ordinary annuity
@app.get(
"/future_value_of_ordinary_due",
tags=["future_value_of_ordinary_due"],
description="Calculating future value of ordinary annuity",
)
def future_value_of_ordinary_due(
periodic_payment: float, number_of_periods: int, effective_interest_rate: float
):
return future_value_of_ordinary_due_task( periodic_payment, number_of_periods, effective_interest_rate)
# Endpoint to calculate future value of the annuity due
@app.post(
"/future_value_of_annuity_due",
tags=["future_value_of_annuity_due"],
description="Calculating future value of annuity due",
)
def future_value_of_annuity_due(
request: futureValueOfAnnuity
):
return future_value_of_annuity_due_task(request.periodic_payment, request.interest_rate, request.number_of_payments)
# Endpoint to calculate present value of the annuity due
@app.get(
"/present_value_of_annuity_due",
tags=["present_value_of_annuity_due"],
description="Calculating present value of annuity due",
)
def present_value_of_annuity_due(
periodic_payment: float, number_of_periods: int, rate_per_period: float
):
return present_value_of_annuity_due_task( periodic_payment, number_of_periods, rate_per_period)
# Endpoint to calculate loan to value
@app.get(
"/loan_to_value",
tags=["loan_to_value"],
description="Calculating loan to value ratio",
)
def loan_to_value(mortgage_value: float, appraised_value: float):
return loan_to_value_task(mortgage_value, appraised_value)
# Endpoint to calculate retention ratio
@app.get(
"/retention_ratio",
tags=["retention_ratio"],
description="Calculating retention ratio",
)
def retention_ratio(net_income: float, dividends: float):
return retention_ratio_task(net_income, dividends)
# Endpoint to calculate tax equivalent yield
@app.get(
"/tax_equivalent_yield",
tags=["tax_equivalent_yield"],
description="Calculating tax equivalent yield",
)
def tax_equivalent_yield(tax_free_yield: float, tax_rate: float):
return tax_equivalent_yield_task(tax_free_yield, tax_rate)
# endpoint to calculate year over year growth
@app.get(
"/year_to_year",
tags=["year_to_year"],
description="Calculating Year to Year Growth",
)
def year_over_year(later_period_value: float, earlier_period_value: float):
return year_over_year_task(later_period_value, earlier_period_value)
@app.get(
"/future_value_of_annuity",
tags=["future_value_of_annuity"],
description="Calculating future worth of annuity",
)
def future_value_of_annuity(
payments_per_period: float, interest_rate: float, number_of_periods: float
):
return future_value_of_annuity_task(
payments_per_period, interest_rate, number_of_periods
)
# endpoint to calculate Balloon Balance of a Loan
@app.get(
"/balloon_balance",