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

Endpoint for debt payoff plannar added #477

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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: 7 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ The initial price of the product or service. |
| POST /margin_of_safety | Calculate margin of safety | - `current_sales` (float): The amount of current sales. |
| | | - `break_even_point` (float): The break_even_point amount. |
|--------------------------- ---|----------------------------------------|---------------------------------------------------------|

| Endpoint | Description | Request Parameters |
|---------------------------|----------------------------------------|---------------------------------------------------------|
| POST /debt_payoff_planner | Calculate debt payoff plan | - `debt_amount` (float): The total amount of debt. |
| | | - `interest_rate` (float): The annual interest rate. |
| | | - `monthly_payment` (float): The fixed monthly payment. |

61 changes: 41 additions & 20 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@
```

\*_GET_ `calculate_lumpsum`
-Required Parameters: `principal`, `interest_rate `, `years`
-Required Parameters: `principal`, `interest_rate`, `years`
-sample output

```py
Expand Down Expand Up @@ -1639,6 +1639,7 @@ Add-function-and-endpoint-to-calculate-lump-sum-mutual-fund-investment
**GET** `/loan-affordability`

- Required parameters : `income`,

`expenses`,
`loan_term`,
`interest_rate`,
Expand All @@ -1660,7 +1661,7 @@ Add-function-and-endpoint-to-calculate-lump-sum-mutual-fund-investment
**GET** `/calculate_bvps`

- Required parameters : `stockholders_equity`,
`preferred_stock`, `average_outstanding_shares`,
`preferred_stock`, `average_outstanding_shares`
- Sample output

```py
Expand All @@ -1678,6 +1679,7 @@ Add-function-and-endpoint-to-calculate-lump-sum-mutual-fund-investment
**GET** `/gratuity-amount`

- Required parameters : `last_salary`,

`tenure_years`,
`tenure_months`,
- Sample Request: `GET`, `http://localhost:8000/calculate_gratuity?last_salary=20000000&tenure_years=10&tenure_months=1`,
Expand Down Expand Up @@ -1709,6 +1711,7 @@ Add-function-and-endpoint-to-calculate-lump-sum-mutual-fund-investment

```


**GET** `/personal_savings`

- Required parameters : 'init','monthly', 'tenure'
Expand Down Expand Up @@ -1746,7 +1749,7 @@ Add-function-and-endpoint-to-calculate-lump-sum-mutual-fund-investment
# GET # Endpoint --> '/mortrage'

Required Paramenters --> princial:int,interest_rate:float,years:int,down_payment:int,property_tax_rate:float,insurance_rate:float
Sample request --> http://127.0.0.1:8000/mortrages?princial=200000&interest_rate=4.5&years=45&down_payment=50000&property_tax_rate=1.3&insurance_rate=0.5
Sample request --> <http://127.0.0.1:8000/mortrages?princial=200000&interest_rate=4.5&years=45&down_payment=50000&property_tax_rate=1.3&insurance_rate=0.5>

Sample Output

Expand All @@ -1765,7 +1768,7 @@ Sample Output

Required Parameters --> birth_date:str,earnings:int,retirement_age:int

Sample request --> http://127.0.0.1:8000/social_securities?birth_date=10-08-2002&earnings=250000&retirement_age=70
Sample request --> <http://127.0.0.1:8000/social_securities?birth_date=10-08-2002&earnings=250000&retirement_age=70>
Sample Output

```py
Expand Down Expand Up @@ -2132,25 +2135,25 @@ Sample Output
**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
"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
"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
}
```

Expand Down Expand Up @@ -2214,7 +2217,7 @@ Sample Output

- Request body : `{
"beginning_inventory": 1000,
"ending_inventory": 2000,
"ending_inventory": 2000,
"beginning_receivables": 100
"ending_receivables": 90,
"beginning_payable": 800,
Expand Down Expand Up @@ -2252,7 +2255,7 @@ Sample Output
"deductible": 500,
"num_claims": 0,
"num_accidents": 1
**POST** `/price-elasticity`
**POST**`/price-elasticity`

- Request body : `{
"initial_price": 10.0,
Expand All @@ -2273,7 +2276,7 @@ Sample Output

- Request body : `{
"beginning_accounts_payable": 110000,
"ending_accounts_payable": 95000,
"ending_accounts_payable": 95000,
"total_credit_purchases": 1110000
}`
- Sample output
Expand Down Expand Up @@ -2362,3 +2365,21 @@ Sample Output
"Margin Of Safety": 8%,
}
```

}```

**POST** `/debt_payoff_planner`
- Request body :
{
"amount_paid": 20.23,
"principle_amount": 30.9,
"months": 5
}
- Sample Output:
```py
{
"Tag": "Simple Interest Rate",
"Total amount paid": 20.23,
"Principle amount": 30.9,
"Interest Paid": -10.67,
"Interest Rate": "-82.87%"
34 changes: 33 additions & 1 deletion helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
from dateutil.relativedelta import relativedelta
from typing import Union
from fastapi import FastAPI, HTTPException, Query


# Function to Calculate Simple Interest Rate
Expand Down Expand Up @@ -2077,7 +2078,6 @@ def interest_coverage_ratio(revenue:float, cost_of_goods_services:float, operati
ratio = EBIT / interest_expense
return ratio


# Function to Calculate Tax Bracket Calculator

def tax_bracket_calculator(income:float, filing_status:str):
Expand Down Expand Up @@ -2112,3 +2112,35 @@ def tax_bracket_calculator(income:float, filing_status:str):
def margin_of_safety(current_sales:float, break_even_point: float):
margin = ((current_sales - break_even_point) / current_sales) * 100
return margin

# Function for Debt Payoff Planner


def debt_payoff_planner(debt_amount: float, interest_rate: float, monthly_payment: float):
if interest_rate <= 0 or monthly_payment <= 0:
raise ValueError("Interest rate and monthly payment must be positive.")

# Convert the interest rate from percentage to decimal
monthly_interest_rate = interest_rate / 100 / 12

months_left = 0
total_interest_paid = 0
remaining_debt = debt_amount

while remaining_debt > 0:
months_left += 1
interest_payment = remaining_debt * monthly_interest_rate
total_interest_paid += interest_payment
remaining_debt += interest_payment - monthly_payment

if remaining_debt <= 0:
break

return {
"Tag": "Debt Payoff Planner",
"Debt Amount": debt_amount,
"Interest Rate": interest_rate,
"Monthly Payment": monthly_payment,
"Months to Pay Off": months_left,
"Total Interest Paid": round(total_interest_paid, 2),
}
48 changes: 47 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi import FastAPI, Depends, HTTPException, status,Query
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.responses import JSONResponse
import jwt
Expand Down Expand Up @@ -2033,3 +2033,49 @@ def tax_bracket_calculator(request: TaxBracketCalculator):
)
def margin_of_safety(request: MarginOfSafety):
return margin_of_safety_task(request.current_sales, request.break_even_point)


# Endpoint for Debt Payoff Planner

app = FastAPI()

@app.get(
"/debt_payoff_planner",
tags=["debt_payoff_planner"],
description="Calculate debt payoff plan",
)
def debt_payoff_planner(
debt_amount: float = Query(..., description="The total amount of debt."),
interest_rate: float = Query(..., description="The annual interest rate (as a percentage)."),
monthly_payment: float = Query(..., description="The fixed monthly payment amount.")
):
try:
if interest_rate <= 0 or monthly_payment <= 0:
raise HTTPException(status_code=400, detail="Interest rate and monthly payment must be positive.")

# Convert the interest rate from percentage to decimal
monthly_interest_rate = interest_rate / 100 / 12

months_left = 0
total_interest_paid = 0
remaining_debt = debt_amount

while remaining_debt > 0:
months_left += 1
interest_payment = remaining_debt * monthly_interest_rate
total_interest_paid += interest_payment
remaining_debt += interest_payment - monthly_payment

if remaining_debt <= 0:
break

return {
"Tag": "Debt Payoff Planner",
"Debt Amount": debt_amount,
"Interest Rate": interest_rate,
"Monthly Payment": monthly_payment,
"Months to Pay Off": months_left,
"Total Interest Paid": round(total_interest_paid, 2),
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
16 changes: 16 additions & 0 deletions tasks/debt_payoff_planner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from fastapi import HTTPException, status
from helpers import functions

def debt_payoff_planner(debt_amount: float, interest_rate: float, monthly_payment: float):
try:
result = functions.debt_payoff_planner(debt_amount, interest_rate, monthly_payment)
return {
"Tag": "Debt Payoff Planner",
"Debt Amount": debt_amount,
"Interest Rate": interest_rate,
"Monthly Payment": monthly_payment,
"Months to Pay Off": result["Months to Pay Off"],
"Total Interest Paid": result["Total Interest Paid"],
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
7 changes: 6 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class SavingGoal(BaseModel):
monthly_contributions : float
interest_rate: float
goal_amount: float

class ModifiedInternalRateOfReturn(BaseModel):
ending_cash_flow: float
initial_cash_flow: float
Expand All @@ -673,3 +673,8 @@ class TaxBracketCalculator(BaseModel):
class MarginOfSafety(BaseModel):
current_sales:float
break_even_point: float

class DebtPayoffPlannerRequest(BaseModel):
debt_amount: float
interest_rate: float
monthly_payment: float