diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index d2a4cbc..a715bd2 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -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. | + diff --git a/ENDPOINTS.md b/ENDPOINTS.md index be417c0..7ce3868 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -1356,7 +1356,7 @@ ``` \*_GET_ `calculate_lumpsum` --Required Parameters: `principal`, `interest_rate `, `years` +-Required Parameters: `principal`, `interest_rate`, `years` -sample output ```py @@ -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`, @@ -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 @@ -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`, @@ -1709,6 +1711,7 @@ Add-function-and-endpoint-to-calculate-lump-sum-mutual-fund-investment ``` + **GET** `/personal_savings` - Required parameters : 'init','monthly', 'tenure' @@ -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 --> Sample Output @@ -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 --> Sample Output ```py @@ -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 } ``` @@ -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, @@ -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, @@ -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 @@ -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%" \ No newline at end of file diff --git a/helpers/functions.py b/helpers/functions.py index ebfbbb7..12d3a3a 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -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 @@ -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): @@ -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), + } diff --git a/main.py b/main.py index 2f5cefc..4798d67 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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)) \ No newline at end of file diff --git a/tasks/debt_payoff_planner.py b/tasks/debt_payoff_planner.py new file mode 100644 index 0000000..c4da0d2 --- /dev/null +++ b/tasks/debt_payoff_planner.py @@ -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) diff --git a/validators/request_validators.py b/validators/request_validators.py index 96bd688..2f5e3b2 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -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 @@ -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 \ No newline at end of file