Skip to content

Commit

Permalink
Merge branch 'main' into rateofreturn
Browse files Browse the repository at this point in the history
  • Loading branch information
shraddha761 authored Jul 11, 2023
2 parents 5d4e700 + e91508a commit 9cf3498
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 10 deletions.
12 changes: 11 additions & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@
| | | - `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_calculator | Rate of return calculator |-`initial_investement` (int): Initial amount of money invested. |
| | | - `final_value` (int): financial asset at the end of a period.|
| | |-`additional_investments` (int): Additional amounts of money invested in an investment |
| | | - `additional_withdrawals` (int): Additional amounts of money withdrawn. |
| ------------------------------- | ------------------------------------ | --------------------------------------------------------- |
| ------------------------------- | ------------------------------------ | --------------------------------------------------------- |

| GET /financial_assest_ratio | Calculate financial assest ratio | - `current_assets` (float): used up within a short period. |
| | | - `current_liabilities` (float): debts that are due . |
| | | - `total_debt` (float): aggregate amount of money. |
| | | - `total_equity`(float): residual interest in the assets. |
| | | - `net_income` (float): net earnings. |
| | | - `total_revenue` (float): sum of all sales. |
| --------------------------- | ---------------------------------------- | --------------------------------------------------------- |

28 changes: 27 additions & 1 deletion ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2154,4 +2154,30 @@ Sample Output
"Daily Operational Expenses": 753.42,
"Defensive Interval Ratio": 92.90
}
```
```

**POST** `/financial_assest_ratio`

- Request body : `{
"current_assets": 500000,
"current_liabilities": 300000,
"total_debt": 200000,
"total_equity": 400000,
"net_income": 100000,
"total_revenue": 800000,
}`
- Sample output

```py
{
"Tag": "Financial assest ratio",
"current_ratio": 1.5,
"debt_to_equity_ratio": 0.8,
"return_on_assets": 0.1,
"return_on_equity": 0.15,
"asset_turnover_ratio": 1.8,
"gross_profit_margin": 0.35,
"net_profit_margin": 0.2,
"price_to_earnings_ratio": 20.5
}
```
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# THIS IS FOR TEST PURPOSE
<h1 align=center> FinTech API v2</h1>

<p align=center>
Expand Down
24 changes: 23 additions & 1 deletion helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,10 +1982,32 @@ def defensive_interval_ratio(cash: float, marketable_securities: float,
ratio = current_assets / daily_operational_expenses
return ratio


# Function to Calculate Rate of return calculator.

def calculate_rate_of_return(initial_investment: int, final_value: int, additional_investments=0, additional_withdrawals=0):
total_invested = initial_investment + additional_investments
final_value -= additional_withdrawals
rate_of_return = (final_value - total_invested) / total_invested
return rate_of_return
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):

current_ratio = current_assets / current_liabilities
debt_to_equity_ratio = total_debt / total_equity
return_on_assets = net_income / total_assets
return_on_equity = net_income / total_equity
profit_margin = net_income / total_revenue

ratios = {
"current_ratio": current_ratio,
"debt_to_equity_ratio": debt_to_equity_ratio,
"return_on_assets": return_on_assets,
"return_on_equity": return_on_equity,
"profit_margin": profit_margin
}

return ratios

28 changes: 25 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@
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 validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, ProfitPercentage, LossPercentage, DefensiveIntervalRatio
from tasks.rate_of_return_calculator import calcualate_rate_of_return

from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, financialAssestRatio
from tasks.financialAssestRatio import financial_assest_ratio


# Creating the app
app = FastAPI(
title="FinTech API",
Expand Down Expand Up @@ -346,9 +351,9 @@ def payback_period(
description="Calculate compound interest amount",
)
def compound_interest(
request: compoundInterest,
request: compoundInterest
):
return compound_interest_task(request.principal_amount, request.interest_rate, request.time)
return compound_interest_task(request.principal_amount, request.interest_rate, request.years ,request.compounding_period)


# Endpoints to calculate certificate of deposit (CD)
Expand Down Expand Up @@ -1878,6 +1883,7 @@ 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 calculator

@app.post("/rate-of-return")
Expand All @@ -1891,4 +1897,20 @@ def calculate_rate_of_return(investment: calcualate_rate_of_return):
return {
"Rate of Return": rate_of_return,
"Percentage Return": percentage_return
}
}

# Endpoint to calculate Financial assest Ratio

@app.post(
"/financial_assest_ratio",
tags=["financial_assest_ratio"],
description="Calculate financial assest Ratio",
)
def financial_assest_ratio(request: financialAssestRatio):
return financial_assest_ratio(request.current_assets,
request.current_liabilities,
request.total_debt,
request.total_equity,
request.net_income,
request.total_revenue)

27 changes: 27 additions & 0 deletions tasks/financialAssestRatio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from helpers import functions
from fastapi import HTTPException, status

def financial_assest_ratio(current_assets: float, current_liabilities: float, total_debt: float,
total_equity: float, net_income: float, total_assets:float, total_revenue: float, gross_profit: float, stock_price: float, earnings_per_share:float):
try:
current_ratio = current_assets / current_liabilities
debt_to_equity_ratio = total_debt / total_equity
return_on_assets = net_income / total_assets
return_on_equity = net_income / total_equity
asset_turnover_ratio = total_revenue / total_assets
gross_profit_margin = gross_profit / total_revenue
net_profit_margin = net_income / total_revenue
price_to_earnings_ratio = stock_price / earnings_per_share
return {
"Tag": "financial assest ratio",
"current_ratio": current_ratio,
"debt_to_equity_ratio": debt_to_equity_ratio,
"return_on_assets": return_on_assets,
"return_on_equity": return_on_equity,
"asset_turnover_ratio": asset_turnover_ratio,
"gross_profit_margin": gross_profit_margin,
"net_profit_margin": net_profit_margin,
"price_to_earnings_ratio": price_to_earnings_ratio,
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
3 changes: 1 addition & 2 deletions tasks/lumpsum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from helpers import functions
from fastapi import HTTPException, status

async def calculate_lumpsum_task(principal: float, interest_rate: float, years: int):
def calculate_lumpsum_task(principal: float, interest_rate: float, years: int):

try:
total_amount = principal * (
Expand Down
13 changes: 12 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,19 @@ class DefensiveIntervalRatio(BaseModel):
annual_operating_expenses: float
non_cash_charges: float


class RateofReturnCalculator(BaseModel):
initial_investment: int
final_value: int
additional_investments: int
additional_withdrawals: int
additional_withdrawals: int

class financialAssestRatio(BaseModel):
current_assets: float
current_liabilities: float
total_debt: float
total_equity: float
net_income: float
total_revenue: float


0 comments on commit 9cf3498

Please sign in to comment.