Skip to content

Commit

Permalink
Merge pull request #480 from roberanegussie/interest_coverage_ratio
Browse files Browse the repository at this point in the history
Interest coverage ratio
  • Loading branch information
ighoshsubho authored Aug 4, 2023
2 parents 8627b4e + e529496 commit 64e64dd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
5 changes: 5 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ The initial price of the product or service. |
| | | - `interest_rate` (float): The annual interest rate on the savings. |
| | | - `goal_amount ` (float): The desired savings goal amount. |
|-----------------------------|----------------------------------------|----------------------------------------------------------------------|
| POST /interest_coverage_ratio | Calculate interest coverage ratio | - `revenue` (float): The amount of income generated through business operations. |
| | | - `cost_of_goods_services` (float): Total amount of costs spent on goods and services.|
| | | - `operating_expenses` (int): The amount of operating expenses. |
| | | - `interest_expense` (int): The cost incurred by an entity for borrowed funds. |
|-------------------------------|----------------------------------------|---------------------------------------------------------|
25 changes: 24 additions & 1 deletion ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2305,4 +2305,27 @@ Sample Output
"months_required": 18,
"total_contributions": 3600,
"interest_earned": 315.27777777777777
}```
}
```
**POST** `/interest_coverage_ratio`
- Request body : `{
"revenue": 150000,
"cost_of_goods_services": 50000,
"operating_expenses": 40000
"interest_expense": 16000
}`
- Sample output
```py
{
"Tag": "Interest Coverage Ratio"
"Revenue": 150000,
"Cost of Goods and Services": 50000,
"Operating Expenses": 40000,
"Interest Expenses": 16000,
"Earnings Before Interest and Taxes": 60000,
"Interest Coverage Ratio": "3.75%",
}
```
8 changes: 8 additions & 0 deletions helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,3 +2068,11 @@ def calculate_modified_internal_rate_of_return(ending_cash_flow: float,
number_of_periods: int):
mirr = ((ending_cash_flow / initial_cash_flow) ** (1 / number_of_periods)) - 1
return mirr*100

# Function to Calculate Interest Coverage Ratio

def interest_coverage_ratio(revenue:float, cost_of_goods_services:float, operating_expenses:float,
interest_expense:float):
EBIT = revenue - cost_of_goods_services - operating_expenses
ratio = EBIT / interest_expense
return ratio
16 changes: 15 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@
from tasks.cash_conversion_cycle import cash_conversion_cycle_task
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PolicyPremium import calculate_policy_premium
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn, SavingGoal, InterestCoverageRatio
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PriceElasticity import calculate_price_elasticity
from tasks.average_payment_period import average_payment_period_task
from tasks.Saving_Goal import saving_goal
from tasks.modified_internal_rate_of_return import calculate_modified_internal_rate_of_return_task
from tasks.interest_coverage_ratio import interest_coverage_ratio_task

# Creating the app
app = FastAPI(
Expand Down Expand Up @@ -274,6 +275,8 @@ def index():
"/loss_percent": "Calculates the loss percentage",
"/average_payment_period": "Calculate Average Payment Period a metric that allows a business to see how long it takes on average to pay its vendors.",
"/modified_internal_rate_of_return": "Calculate modified internal rate of return",
"/interest_coverage_ratio": "Calculates interest coverage ratio",

},
}

Expand Down Expand Up @@ -1996,3 +1999,14 @@ def saving_goal(request: SavingGoal):
request.monthly_contributions ,
request.interest_rate,
request.goal_amount )

# Endpoint to calculate Interest Coverage Ratio

@app.post(
"/interest_coverage_ratio",
tags=["interest_coverage_ratio"],
description="Calculates interest coverage ratio",
)
def interest_coverage_ratio(request: InterestCoverageRatio):
return interest_coverage_ratio_task(request.revenue, request.cost_of_goods_services,
request.operating_expenses, request.interest_expense)
21 changes: 21 additions & 0 deletions tasks/interest_coverage_ratio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from helpers import functions
from fastapi import HTTPException, status


def interest_coverage_ratio_task(revenue:float, cost_of_goods_services:float, operating_expenses:float, interest_expense:float):
try:
EBIT = revenue - cost_of_goods_services - operating_expenses
ratio = functions.interest_coverage_ratio(revenue, cost_of_goods_services, operating_expenses, interest_expense)
return{
"Tag": "Interest Coverage Ratio",
"Revenue": revenue,
"Cost of Goods and Services": cost_of_goods_services,
"Operating Expenses": operating_expenses,
"Interest Expenses": interest_expense,
"Earnings Before Interest and Taxes": EBIT,
"Interest Coverage Ratio": f"{ratio}%",
}

except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
6 changes: 6 additions & 0 deletions validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,9 @@ class ModifiedInternalRateOfReturn(BaseModel):
ending_cash_flow: float
initial_cash_flow: float
number_of_periods: int

class InterestCoverageRatio(BaseModel):
revenue:float
cost_of_goods_services:float
operating_expenses:float
interest_expense:float

0 comments on commit 64e64dd

Please sign in to comment.