diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 4429a0e..0542f4d 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -66,3 +66,8 @@ The initial price of the product or service. | | | | - `ending_inventory` (float): The final amount of accounts payable ending the cycle. | | | | - `total_credit_purchases` (float): The amount of purchases on credit during the cycle. | |-----------------------------|----------------------------------------|---------------------------------------------------------------------| +| GET /saving_goal | Saving Goal Calculator | - `current_savings` (float): The current amount of savings. | +| | | - `monthly_contributions` (float): The amount of money contributed each month towards the savings goal. | +| | | - `interest_rate` (float): The annual interest rate on the savings. | +| | | - `goal_amount ` (float): The desired savings goal amount. | +|-----------------------------|----------------------------------------|----------------------------------------------------------------------| diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 6053276..9a3aeac 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2269,7 +2269,6 @@ Sample Output "price_elasticity": -1.5 } ``` - **POST** `/average_payment_period` - Request body : `{ @@ -2289,3 +2288,21 @@ Sample Output "Average Payment Period": "33.7days", } ``` + +**POST** `/saving_goal ` + +- Request body : `{ + "current_savings": 100, + "monthly_contributions ": 200, + "interest_rate" 5, + "goal_amount" 5000 + }` + - Sample output + +```py +{ + "Tag": "Saving Goal Calculator", + "months_required": 18, + "total_contributions": 3600, + "interest_earned": 315.27777777777777 + }``` diff --git a/helpers/functions.py b/helpers/functions.py index 8425d51..acad33d 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -2055,10 +2055,16 @@ def average_payment_period(beginning_accounts_payable: float, ending_accounts_pa app = average_accounts_payable / (total_credit_purchases / 365) return app +# Function to Saving Goal Calculator + +def saving_goal(current_savings: float, monthly_contributions: float, interest_rate: float, goal_amount: float): + savings_ratio = current_savings / goal_amount + return savings_ratio + # Function to calculate Modified Internal Rate of Return (MIRR) def calculate_modified_internal_rate_of_return(ending_cash_flow: float, initial_cash_flow: float, number_of_periods: int): mirr = ((ending_cash_flow / initial_cash_flow) ** (1 / number_of_periods)) - 1 - return mirr*100 \ No newline at end of file + return mirr*100 diff --git a/main.py b/main.py index e54df32..6382da1 100644 --- a/main.py +++ b/main.py @@ -139,9 +139,9 @@ 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 - # Creating the app app = FastAPI( title="FinTech API", @@ -1974,7 +1974,6 @@ def price_elasticity(request: PriceElasticity): request.initial_quantity, request.final_quantity ) - # Endpoint to calculate Average Payment Period @app.post( "/average_payment_period", @@ -1985,3 +1984,15 @@ def average_payment_period(request: AveragePaymentPeriod): return average_payment_period_task(request.beginning_accounts_payable , request.ending_accounts_payable , request.total_credit_purchases) +# Endpoint to calculate Saving Goal + +@app.post( + "/saving_goal", + tags=["saving_goal"], + description="Calculate Saving Goal", +) +def saving_goal(request: SavingGoal): + return saving_goal(request.current_savings , + request.monthly_contributions , + request.interest_rate, + request.goal_amount ) diff --git a/tasks/Saving_Goal.py b/tasks/Saving_Goal.py new file mode 100644 index 0000000..9002207 --- /dev/null +++ b/tasks/Saving_Goal.py @@ -0,0 +1,20 @@ +from fastapi import HTTPException, status + +def saving_goal(current_savings: float, monthly_contributions: float, interest_rate: float, goal_amount: float): + try: + while current_savings < goal_amount: + months_required += 1 + total_contributions += monthly_contributions + current_savings += monthly_contributions + interest_earned += (current_savings * interest_rate / 100) / 12 + + if current_savings >= goal_amount: + + return { + "months_required": months_required, + "total_contributions": total_contributions, + "interest_earned": interest_earned, + + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/validators/request_validators.py b/validators/request_validators.py index 100c2d7..b58f3c4 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -649,7 +649,13 @@ class AveragePaymentPeriod(BaseModel): ending_accounts_payable: float total_credit_purchases: float +class SavingGoal(BaseModel): + current_savings: float + monthly_contributions : float + interest_rate: float + goal_amount: float + class ModifiedInternalRateOfReturn(BaseModel): ending_cash_flow: float initial_cash_flow: float - number_of_periods: int \ No newline at end of file + number_of_periods: int