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

Financial Goal Planner #500

Open
wants to merge 2 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
6 changes: 6 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
|----------------------------|----------------------------------------|----------------------------------------------------------------------|
29 changes: 29 additions & 0 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2362,3 +2362,32 @@ 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": 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}
]
}
25 changes: 25 additions & 0 deletions helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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)
24 changes: 24 additions & 0 deletions tasks/FinancialGoalPlanner.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading