diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 8e181ff0..f0719c3d 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -26,6 +26,12 @@ | | | - `net_receivables` (float): The amount of net_receivables.| | | | - `annual_operating_expenses` (float): The amount of annual_operating_expenses.| | | | - `non_cash_charges` (float): The amount of non cash charges.| +|-----------------------------|----------------------------------------------|-----------------------------------------------------------| +| post /rate_of_return | Calculate Rate of Return | - `initial_investment` (float): Initial amount invested. | +| | | - `final_value` (float): the value of the investment at the end of the investment. | +| | | - `time_period` (float): The number of months. | +| | | - `cash_flows` (float): A list of cash flows over the investment period. | +| | | - `holding_period` (float): The specific holding period of the investment. | | --------------------------- | ---------------------------------------- | --------------------------------------------------------- | | GET /financial_assest_ratio | Calculate financial assest ratio | - `current_assets` (float): used up within a short period. | | | | - `current_liabilities` (float): debts that are due . | diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 6c05f837..4cdd7567 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2133,6 +2133,14 @@ Sample Output "Loss Percentage": 6.67, } ``` +**POST** `/rate_return_calculator` + +- Request body : `{ + "initial_investment": 10000, + "final_value": 12500, + "time_period": 3, + "cash_flows": [500, 800, -200], + "holding_period": 2, **POST** `/financial_assest_ratio` @@ -2148,6 +2156,10 @@ Sample Output ```py { + "Tag": "Rate of return", + "rate_of_return": 25.0, + "annualized_return": 8.333333333333334, + "holding_period_return": 50.0, "Tag": "Financial assest ratio", "current_ratio": 1.5, "debt_to_equity_ratio": 0.8, diff --git a/helpers/functions.py b/helpers/functions.py index 1a3271ba..a310dd63 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -1982,7 +1982,13 @@ def defensive_interval_ratio(cash: float, marketable_securities: float, ratio = current_assets / daily_operational_expenses return ratio -## Function to Calculate Financial Assest Ratio +# Function to Calculate Debt Service Coverage Ratio. + +def rate_of_return(initial_investment: float, final_value: float ): + rate_of_return = ((final_value - initial_investment) / initial_investment) * 100 + return rate_of_return + + ## Function to Calculate Financial Assest Ratio def calculate_financial_asset_ratios(current_assets, current_liabilities, total_debt, total_equity, net_income, total_revenue, total_assets): diff --git a/main.py b/main.py index ed9d2cb9..95181d4d 100644 --- a/main.py +++ b/main.py @@ -131,8 +131,9 @@ 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 validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, financialAssestRatio +from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio from tasks.financialAssestRatio import financial_assest_ratio # Creating the app @@ -1881,6 +1882,19 @@ def defensive_interval_ratio(request: DefensiveIntervalRatio): return defensive_interval_ratio_task(request.cash, request.marketable_securities, request.net_receivables, request.annual_operating_expenses , request.non_cash_charges) +# Endpoint to calculate Rate of return + +@app.post( + "/rate_of_return", + tags=["rate_of_return"], + description="Calculate Rate of return", +) +def rate_of_return(request: RateofReturn): + return calculate_rate_of_return(request.initial_investment, + request.final_value, + request.cash_flows, + request.time_period, + request.holding_period) # Endpoint to calculate Financial assest Ratio @app.post( @@ -1896,6 +1910,7 @@ def financial_assest_ratio(request: financialAssestRatio): request.net_income, request.total_revenue) + # Endpoint to calculate Cash Conversion Cycle @app.post( @@ -1907,4 +1922,3 @@ def cash_conversion_cycle(request: CashConversionCycle): return cash_conversion_cycle_task(request.beginning_inventory , request.ending_inventory , request.beginning_receivables, request.ending_receivables , request.beginning_payable, request.ending_payable , request.net_credit_sales , request.cost_of_goods_sold) - diff --git a/tasks/RateofReturn.py b/tasks/RateofReturn.py new file mode 100644 index 00000000..c3c04429 --- /dev/null +++ b/tasks/RateofReturn.py @@ -0,0 +1,25 @@ +from helpers import functions +from fastapi import HTTPException, status + +def calculate_rate_of_return(initial_investment: float, final_value: float, cash_flows: float, +time_period: float, holding_period: float): + try: + net_cash_flows = sum(cash_flows) + final_value += net_cash_flows + + if holding_period > 0: + rate_of_return = ((final_value - initial_investment) / (initial_investment + net_cash_flows)) * 100 + holding_period_return = ((final_value - initial_investment) / initial_investment) * 100 + else: + rate_of_return = ((final_value - initial_investment) / initial_investment) * 100 + holding_period_return = rate_of_return + + annualized_return = rate_of_return / time_period + return { + "Tag": "Rate of return", + "rate_of_return": rate_of_return, + "annualized_return": annualized_return, + "holding_period_return": holding_period_return + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/validators/request_validators.py b/validators/request_validators.py index 3eb5b473..29d2b423 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -604,6 +604,13 @@ class DefensiveIntervalRatio(BaseModel): annual_operating_expenses: float non_cash_charges: float +class RateofReturn(BaseModel): + initial_investment: float + final_value: float + cash_flows: float + time_period: float + holding_period: float + class financialAssestRatio(BaseModel): current_assets: float current_liabilities: float @@ -621,4 +628,3 @@ class CashConversionCycle(BaseModel): ending_payable: float cost_of_goods_sold: float net_credit_sales: float - \ No newline at end of file