From 5c8401416d06b9635a3861090b78ef53b5954a10 Mon Sep 17 00:00:00 2001 From: Shraddha Singh Date: Wed, 9 Aug 2023 08:11:01 +0530 Subject: [PATCH 1/2] Financial Goal Planner --- DOCUMENTATION.md | 6 ++++++ ENDPOINTS.md | 15 +++++++++++++++ helpers/functions.py | 25 +++++++++++++++++++++++++ main.py | 15 +++++++++++++-- tasks/FinancialGoalPlanner.py | 24 ++++++++++++++++++++++++ validators/request_validators.py | 6 ++++++ 6 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 tasks/FinancialGoalPlanner.py diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index d2a4cbc7..afd9a727 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -82,3 +82,9 @@ 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. | |--------------------------- ---|----------------------------------------|---------------------------------------------------------| +| GET /financial_goal_planner | Financial Goal Planner Calculator | - `initial_savings_amount`(int): +The initial amount of savings. | +| | | - `monthly_savings_amount` (int): The amount you plan to save. | +| | | - `target_savings_amount` (int): The total amount of savings. | +| | | - `timeframe` (int): The fiduration in which you plan to achieve. | +|----------------------------|----------------------------------------|----------------------------------------------------------------------| \ No newline at end of file diff --git a/ENDPOINTS.md b/ENDPOINTS.md index be417c04..d43b79b5 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2362,3 +2362,18 @@ Sample Output "Margin Of Safety": 8%, } ``` +**POST** `/financial_goal_planner` +- Request body : `{ + "initial_savings_amount": 1000, + "monthly_savings_amount": 200, + "target_savings_amount": 5000, + "timeframe": 12 +}` +- Sample output +```py +{ + "Tag": "financial goal planner", + "monthly_savings_goal": 333 + "total_savings_goal": 4000 + "savings_schedule": +} diff --git a/helpers/functions.py b/helpers/functions.py index ebfbbb77..1844f7a6 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -2112,3 +2112,28 @@ 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 to Calculate financial goal planner + +def financial_goal_planner(initial_savings:float, monthly_savings:float, target_savings:float, timeframe:float): + total_savings_goal = target_savings - initial_savings + months = timeframe if isinstance(timeframe, int) else timeframe * 12 + monthly_savings_goal = total_savings_goal / months + + savings_schedule = [] + current_savings = initial_savings + + for month in range(1, months + 1): + current_savings += monthly_savings + savings_schedule.append((month, current_savings)) + + savings_ratio = current_savings / target_savings + + output = { + "monthly_savings_goal": monthly_savings_goal, + "total_savings_goal": total_savings_goal, + "savings_schedule": savings_schedule, + "savings_ratio": savings_ratio + } + + return output diff --git a/main.py b/main.py index 2f5cefc2..96270b9a 100644 --- a/main.py +++ b/main.py @@ -135,7 +135,7 @@ 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, SavingGoal, InterestCoverageRatio, MarginOfSafety, TaxBracketCalculator +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, MarginOfSafety, TaxBracketCalculator, FinancialGoalPlanner from tasks.financialAssestRatio import financial_assest_ratio from tasks.PriceElasticity import calculate_price_elasticity from tasks.average_payment_period import average_payment_period_task @@ -144,7 +144,7 @@ from tasks.interest_coverage_ratio import interest_coverage_ratio_task from tasks.tax_bracket_calculator import tax_bracket_calculator from tasks.margin_of_safety import margin_of_safety_task - +from tasks.FinancialGoalPlanner import financial_goal_palnner # Creating the app app = FastAPI( title="FinTech API", @@ -2033,3 +2033,14 @@ 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 to calculate financial Goal Planner + +@app.post( + "/financial_goal_planner", + tags=["financial_goal_planner"], + description="Calculates financial Goal Planner", +) +def financial_goal_planner(request: FinancialGoalPlanner): + return financial_goal_planner(request.initial_savings_amount, request.monthly_savings_amount, + request.target_savings_amount, request.timeframe) \ No newline at end of file diff --git a/tasks/FinancialGoalPlanner.py b/tasks/FinancialGoalPlanner.py new file mode 100644 index 00000000..8e8e7580 --- /dev/null +++ b/tasks/FinancialGoalPlanner.py @@ -0,0 +1,24 @@ +from helpers import functions +from fastapi import HTTPException, status + +def financial_goal_palnner(initial_savings_amount: int, monthly_savings_amount: int, target_savings_amount: int, +timeframe: int): + try: + total_savings_goal = target_savings_amount - initial_savings_amount + months = timeframe if isinstance(timeframe, int) else timeframe * 12 + monthly_savings_goal = total_savings_goal / months + + savings_schedule = [] + current_savings = initial_savings_amount + + for month in range(1, months + 1): + current_savings += monthly_savings_amount + savings_schedule.append((month, current_savings)) + return { + "Tag": "financial goal planner", + "monthly_savings_goal": monthly_savings_goal, + "total_savings_goal": total_savings_goal, + "savings_schedule": savings_schedule + } + 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 96bd688d..c941bab2 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -673,3 +673,9 @@ class TaxBracketCalculator(BaseModel): class MarginOfSafety(BaseModel): current_sales:float break_even_point: float + +class FinancialGoalPlanner(BaseModel): + initial_saving_amount: int + monthly_savings_amount: int + target_savings_amount: int + timeframe: int \ No newline at end of file From 4927ccd306d920f2b6cde0253ee2ec4d7d969412 Mon Sep 17 00:00:00 2001 From: Shraddha Singh Date: Wed, 9 Aug 2023 08:16:07 +0530 Subject: [PATCH 2/2] Financial goal planner --- ENDPOINTS.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ENDPOINTS.md b/ENDPOINTS.md index d43b79b5..49f1bc8e 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2374,6 +2374,20 @@ Sample Output { "Tag": "financial goal planner", "monthly_savings_goal": 333 - "total_savings_goal": 4000 - "savings_schedule": + "total_savings_goal": 5000 + "savings_ratio": 1.0 + "savings_schedule":[ + {"Month": 1, "Savings": 1200}, + {"Month": 2, "Savings": 1400}, + {"Month": 3, "Savings": 1600}, + {"Month": 4, "Savings": 1800}, + {"Month": 5, "Savings": 2000}, + {"Month": 6, "Savings": 2200}, + {"Month": 7, "Savings": 2400}, + {"Month": 8, "Savings": 2600}, + {"Month": 9, "Savings": 2800}, + {"Month": 10, "Savings": 3000}, + {"Month": 11, "Savings": 3200}, + {"Month": 12, "Savings": 3400} + ] }