diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b74262..c6e9ae8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -174,7 +174,7 @@ def simple_interest_rate(request: SimpleInterestRateRequest): "Principle amount": 30.9, "Interest Paid": -10.669999999999998, "Interest Rate": "-82.87378640776697%" -} +} ``` ``` +Update the Docs ``` diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 53b5c3b..a319540 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -66,7 +66,12 @@ 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. | +|-----------------------------|----------------------------------------|----------------------------------------------------------------------| |---------------------------|----------------------------------------|---------------------------------------------------------| | GET /ppf_calculator | Calculate Public Provident Fund(PPF) | - `depos` (int): Annual Deposit. | | | | - `tenure` (int): Total years of investment. | -| | | - `interest` (float): percentage interest rate. | \ No newline at end of file +| | | - `interest` (float): percentage interest rate. | diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 4fc8370..3b62111 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2269,7 +2269,6 @@ Sample Output "price_elasticity": -1.5 } ``` - **POST** `/average_payment_period` - Request body : `{ @@ -2291,7 +2290,24 @@ Sample Output ``` +**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 + }``` + **POST** `/ppf_calculator` - Request body : `{ @@ -2308,4 +2324,4 @@ Sample Output "No. of Years": 15, "percentage interst Rate": 7.1, "Total Value of PPF": "13560" -} \ No newline at end of file +} diff --git a/helpers/functions.py b/helpers/functions.py index 1f2ad55..8bb1bb8 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -2055,6 +2055,12 @@ 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, @@ -2071,3 +2077,4 @@ def ppf_calculator(depos:int, a=1+interest/100 total_value= depos*(((a**tenure) - 1)/(interest/100))*a return total_value + diff --git a/main.py b/main.py index 8be2f27..5372045 100644 --- a/main.py +++ b/main.py @@ -139,10 +139,10 @@ 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.PPFCalculator import ppf_calculator - # Creating the app app = FastAPI( title="FinTech API", @@ -1976,7 +1976,6 @@ def price_elasticity(request: PriceElasticity): request.initial_quantity, request.final_quantity ) - # Endpoint to calculate Average Payment Period @app.post( "/average_payment_period", @@ -1987,6 +1986,20 @@ 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 ) + #Endpoint to Calculate Public Provident Fund(PPF) @app.post( @@ -1994,5 +2007,6 @@ def average_payment_period(request: AveragePaymentPeriod): tags=["ppf_calculator"], description="Calculates Public Provident Fund(PPF)", ) -def simple_interest_rate(request: PPFCalculator): - return simple_interest_rate_task(request.depos, request.tenure, request.interest) \ No newline at end of file +def ppf_calculator(request: PPFCalculator): + return ppf_calculator(request.depos, request.tenure, request.interest) + 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 83496a4..933303e 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -649,12 +649,18 @@ 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 -class PPFcalculator(BaseModel): +class PPFCalculator(BaseModel): depos:int tenure:int interest:float