Skip to content

Commit

Permalink
Merge pull request #404 from roberanegussie/debtServiceCoverageRatio
Browse files Browse the repository at this point in the history
Debt service coverage ratio
  • Loading branch information
ighoshsubho authored Jul 4, 2023
2 parents ad2856e + c05e185 commit c149751
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 6 deletions.
9 changes: 8 additions & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
| --------------------------- | ---------------------------------------- | --------------------------------------------------------- |
| POST /capm | Calculate Capital Asset Pricing Model (CAPM) | - `risk_free_return` (float): Risk-free rate of return. |
| | | - `sensitivity` (float): Asset's sensitivity. |
| | | - `expected_market_return` (float): Expected return of the market. |
| | | - `expected_market_return` (float): Expected return of the market. |
| --------------------------- | ---------------------------------------- | --------------------------------------------------------- |
| POST /debt_service_coverage_ratio | Calculate Debt Service Coverage Ratio | - `revenue` (float): Amount of Company Revenue. |
| | | - `operating_expenses` (float): Cost of operating expenses.|
| | | - `interest` (float): Amount of interest to be paid |
| | | - `tax_rate` (float): The tax rate applied. |
| | | - `principal` (float): Amount of principal borrowed. |
| ------------------------------- | ------------------------------------ | --------------------------------------------------------- |
28 changes: 27 additions & 1 deletion ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2050,4 +2050,30 @@ Sample Output
"Asset's sensitivity": 6,
"Expected return of the market": 87,
"Expected return on the asset": "92.0%"
}
}
```

**POST** `/debt_service_coverage_ratio`

- Request body : `{
"revenue": 143528.79,
"operating_expenses": 62148.63,
"interest": 4765.32,
"tax_rate": 20,
"principal": 60371.61
}`
- Sample output

```py
{
"Tag": "Debt Service Coverage Ratio",
"Revenue": 143528.79,
"Operating Expenses": 62148.63,
"Interest": 4765.32,
"Tax Rate": 0.2,
"Principal": 90371.61,
"Net Operating Income": 81380.16,
"Total Debt Service": 64183.866,
"Debt Service Coverage Ratio": 1.34
}
```
12 changes: 11 additions & 1 deletion helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,4 +1951,14 @@ def net_worth_calculation(assets: float, liabilities: float, loans: float, mortg

def capm_calculation(risk_free_return:float, sensitivity:float, expected_market_return:float):
expected_asset_return = risk_free_return + sensitivity * (expected_market_return - risk_free_return)
return expected_asset_return
return expected_asset_return

# Function to Calculate Debt Service Coverage Ratio.

def debt_service_coverage_ratio(revenue: float, operating_expenses: float, interest: float,
tax_rate: float, principal: float):
tax_rate = tax_rate / 100
net_operating_income = revenue - operating_expenses
total_debt_service = (interest * (1 - tax_rate)) + principal
ratio = net_operating_income / total_debt_service
return ratio
19 changes: 17 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
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 validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest
from tasks.debt_service_coverage_ratio import debt_service_coverage_ratio_task
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio

# Creating the app
app = FastAPI(
Expand Down Expand Up @@ -1826,4 +1827,18 @@ def accounts_payable_turnover_ratio(total_supply_purchases: float,
description="Estimate the expected return on an investment.",
)
def capm(request: capmRequest):
return calculate_capm(request.risk_free_return, request.sensitivity, request.expected_market_return)
return calculate_capm(request.risk_free_return, request.sensitivity, request.expected_market_return)

# Endpoint to calculate Debt Service Coverage Ratio

@app.post(
"/debt_service_coverage_ratio",
tags=["debt_service_coverage_ratio"],
description="Calculate Debt Service Coverage Ratio",
)
def debt_service_coverage_ratio(request: DebtServiceCoverageRatio):
return debt_service_coverage_ratio_task(request.revenue,
request.operating_expenses,
request.interest,
request.tax_rate,
request.principal)
26 changes: 26 additions & 0 deletions tasks/debt_service_coverage_ratio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from helpers import functions
from fastapi import HTTPException, status

def debt_service_coverage_ratio_task(revenue: float, operating_expenses: float, interest: float,
tax_rate: float, principal: float):
try:
net_operating_income = revenue - operating_expenses
total_debt_service = (interest * (1 - tax_rate)) + principal
ratio = functions.debt_service_coverage_ratio(revenue,
operating_expenses,
interest,
tax_rate,
principal)
return {
"Tag": "Debt Service Coverage Ratio",
"Revenue": revenue,
"Operating Expenses": operating_expenses,
"Interest": interest,
"Tax Rate": tax_rate,
"Principal": principal,
"Net Operating Income": net_operating_income,
"Total Debt Service": total_debt_service,
"Debt Service Coverage Ratio": ratio
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
9 changes: 8 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,4 +860,11 @@ class calculateBvps(BaseModel):
class capmRequest(BaseModel):
risk_free_return:float
sensitivity:float
expected_market_return:float
expected_market_return:float

class DebtServiceCoverageRatio(BaseModel):
revenue: float
operating_expenses: float
interest: float
tax_rate: float
principal: float

0 comments on commit c149751

Please sign in to comment.