Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defensive interval ratio #410

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
| | | - `interest` (float): Amount of interest to be paid |
| | | - `tax_rate` (float): The tax rate applied. |
| | | - `principal` (float): Amount of principal borrowed. |
| ------------------------------- | ------------------------------------ | --------------------------------------------------------- |
| ------------------------------- | ------------------------------------ | --------------------------------------------------------- |
| POST /defensive_interval_ratio | Calculate Defensive Interval Ratio | - `cash` (float): The amount of cash on hand. |
| | | - `marketable_securities` (float): The amount of marketable_securities.|
| | | - `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.|
27 changes: 26 additions & 1 deletion ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2076,4 +2076,29 @@ Sample Output
"Total Debt Service": 64183.866,
"Debt Service Coverage Ratio": 1.34
}
```
```
**POST** `/defensive_interval_ratio`

- Request body : `{
"cash": 40000.00,
"marketable_securities": 20000.00,
"net_receivables": 10000.00,
"annual_operating_expenses": 300000.00,
"non_cash_charges": 25000.00
}`
- Sample output

```py
{
"Tag": "Defensive Interval Ratio",
"Cash": 40000.00,
"Marketable Securites": 20000.00,
"Net Receivables": 10000.00,
"Annual Operating Expenses": 300000.00,
"Non Cash Charges": 25000.00,
"Current Assets": 70000.0,
"Daily Operational Expenses": 753.42,
"Defensive Interval Ratio": 92.90
}
```

12 changes: 11 additions & 1 deletion helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1961,4 +1961,14 @@ def debt_service_coverage_ratio(revenue: float, operating_expenses: float, inter
net_operating_income = revenue - operating_expenses
total_debt_service = (interest * (1 - tax_rate)) + principal
ratio = net_operating_income / total_debt_service
return ratio
return ratio

## Function to Calculate Defensive Interval Ratio

def defensive_interval_ratio(cash: float, marketable_securities: float,
net_receivables: float, annual_operating_expenses: float, non_cash_charges: float):
current_assets = cash + marketable_securities + net_receivables
daily_operational_expenses = (annual_operating_expenses - non_cash_charges) / 365
ratio = current_assets / daily_operational_expenses
return ratio

17 changes: 15 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
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 validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity
from tasks.defensive_interval_ratio import defensive_interval_ratio_task
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, DefensiveIntervalRatio

# Creating the app
app = FastAPI(
Expand Down Expand Up @@ -1842,4 +1843,16 @@ def debt_service_coverage_ratio(request: DebtServiceCoverageRatio):
request.operating_expenses,
request.interest,
request.tax_rate,
request.principal)
request.principal)

# Endpoint to calculate Defensive Interval Ratio

@app.post(
"/defensive_interval_ratio",
tags=["defensive_interval_ratio"],
description="Calculate Defensive Interval Ratio",
)
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)

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

def defensive_interval_ratio_task(cash: float, marketable_securities: float, net_receivables: float,
annual_operating_expenses: float, non_cash_charges: float):
try:
current_assets = cash + marketable_securities + net_receivables
daily_operational_expenses = (annual_operating_expenses - non_cash_charges) / 365
ratio = functions.defensive_interval_ratio(cash, marketable_securities, net_receivables, annual_operating_expenses, non_cash_charges)
return {
"Tag": "Defensive Interval Ratio",
"Cash": cash,
"Marketable Securites": marketable_securities,
"Net Receivables": net_receivables,
"Annual Operating Expenses": annual_operating_expenses,
"Non Cash Charges": non_cash_charges,
"Current Assets": current_assets,
"Daily Operational Expenses": daily_operational_expenses,
"Defensive Interval Ratio": ratio
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)

10 changes: 9 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,4 +867,12 @@ class DebtServiceCoverageRatio(BaseModel):
operating_expenses: float
interest: float
tax_rate: float
principal: float
principal: float

class DefensiveIntervalRatio(BaseModel):
cash: float
marketable_securities: float
net_receivables: float
annual_operating_expenses: float
non_cash_charges: float