From f0f211601b8b60f0b0d36cbe78e6718c0cdc8a17 Mon Sep 17 00:00:00 2001 From: Ritik Raj Date: Fri, 30 Jun 2023 20:26:15 +0530 Subject: [PATCH] removed redundant compounded annual growth rate --- ENDPOINTS.md | 14 ------------- helpers/functions.py | 18 ----------------- main.py | 28 -------------------------- tasks/compound_annual_growth_rate.py | 19 ----------------- tasks/compounded_annual_growth_rate.py | 20 ------------------ tests/test_main.py | 14 ------------- 6 files changed, 113 deletions(-) delete mode 100644 tasks/compound_annual_growth_rate.py delete mode 100644 tasks/compounded_annual_growth_rate.py diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 0b1bb25f..eef07088 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -105,20 +105,6 @@ } ``` -**GET** `/compounded_annual_growth_rate` - -- Required parameters : `end_investment_value`, `initial_investment_value` and`years` -- Sample output - -```py -{ - "Tag":"Compounded Annual Growth Rate", - "End investment value":100000, - "Initial investment value":70000, - "Years":3, - "Compunded Annual Growth Rate":0.12624788 -} -``` **GET** `/asset_portfolio` diff --git a/helpers/functions.py b/helpers/functions.py index 7ba95169..354e7750 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -101,15 +101,6 @@ def return_on_investment(current_value_of_investment: float, cost_of_investment: return decimal_to_percent(roi) -# Function to calculate Compounded Annual Growth Rate (CAGR) -def compounded_annual_growth_rate( - end_investment_value: float, initial_investment_value: float, years: int -): - n = 1 / years - cagr = (end_investment_value / initial_investment_value) ** n - 1 - return cagr - - # Function to calculate Jensens Alpha def jensens_alpha( return_from_investment: float, @@ -650,15 +641,6 @@ def present_value_of_annuity_due( return present_value_of_annuity_due -# function to calculate compound annual growth rate -def compound_annual_growth_rate_1( - ending_value: float, beginning_value: float, number_of_periods: float -): - a = (ending_value // beginning_value) ** (1 // number_of_periods) - cagr = a - 1 - return cagr - - # Function to calculate loan to value def loan_to_value(mortage_value: float, appraised_value: float): ratio = mortage_value / appraised_value diff --git a/main.py b/main.py index 6b97957f..5b56c1e1 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,6 @@ 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.compounded_annual_growth_rate import compounded_annual_growth_rate_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 @@ -48,7 +47,6 @@ 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.compound_annual_growth_rate import compound_annual_growth_rate_1_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 @@ -171,7 +169,6 @@ def index(): "/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", @@ -381,18 +378,6 @@ def return_on_investment(current_value_of_investment: float, cost_of_investment: return return_on_investment_task(current_value_of_investment, cost_of_investment) -# 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 -): - return compounded_annual_growth_rate_task( end_investment_value, initial_investment_value, years) - - # Endpoint to calculate Jensen's Alpha @app.get( "/jensens_alpha", @@ -933,19 +918,6 @@ def present_value_of_annuity_due( return present_value_of_annuity_due_task( periodic_payment, number_of_periods, rate_per_period) -@app.get( - "/compound_annual_growth_rate", - tags=["compound_annual_growth_rate"], - description="Calculating compound annual growth rate", -) -def compound_annual_growth_rate_1( - ending_value: float, beginning_value: float, number_of_periods: float -): - return compound_annual_growth_rate_1_task( - ending_value, beginning_value, number_of_periods - ) - - # Endpoint to calculate loan to value @app.get( "/loan_to_value", diff --git a/tasks/compound_annual_growth_rate.py b/tasks/compound_annual_growth_rate.py deleted file mode 100644 index 58d21228..00000000 --- a/tasks/compound_annual_growth_rate.py +++ /dev/null @@ -1,19 +0,0 @@ -from helpers import functions -from fastapi import HTTPException, status - -def compound_annual_growth_rate_1_task( - ending_value: float, beginning_value: float, number_of_periods: float -): - try: - cagr = functions.compound_annual_growth_rate_1( - ending_value, beginning_value, number_of_periods - ) - return { - "Tag": "compound annual growth rate 1", - "ending_value": ending_value, - "beginning value": beginning_value, - "Number of periods": number_of_periods, - "compound annual growth rate": f"{cagr}%", - } - except: - return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/tasks/compounded_annual_growth_rate.py b/tasks/compounded_annual_growth_rate.py deleted file mode 100644 index aeaa0d15..00000000 --- a/tasks/compounded_annual_growth_rate.py +++ /dev/null @@ -1,20 +0,0 @@ -from helpers import functions -from fastapi import HTTPException, status - -def compounded_annual_growth_rate_task( - 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) \ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py index d8531a11..6c44a0b6 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -222,20 +222,6 @@ def test_return_on_investment(): "Return on Investment": "1891.1764705882351%" } -def test_compounded_annual_growth_rate(): - response = client.get( - "http://127.0.0.1:8000/compounded_annual_growth_rate?end_investment_value=456&initial_investment_value=113&years=4" - ) - assert response.status_code == status.HTTP_200_OK - - assert response.json() == { - "Tag": "Compounded Annual Growth Rate", - "End investment value": 456, - "Initial investment value": 113, - "Years": 4, - "Compounded Annual Growth Rate": "0.4173320235605005%" -} - def test_jensens_alpha(): response = client.get( "http://127.0.0.1:8000/jensens_alpha?return_from_investment=4566&return_of_appropriate_market_index=32&risk_free_rate=3&beta=45"