Skip to content

Commit

Permalink
Merge pull request #457 from Killer2OP/Saving
Browse files Browse the repository at this point in the history
[ADDED]: Saving Goal Endpoint
  • Loading branch information
ighoshsubho authored Jul 29, 2023
2 parents e8d5a6e + b8c481e commit 6f12cac
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
5 changes: 5 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
|-----------------------------|----------------------------------------|----------------------------------------------------------------------|
19 changes: 18 additions & 1 deletion ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,6 @@ Sample Output
"price_elasticity": -1.5
}
```
**POST** `/average_payment_period`
- Request body : `{
Expand All @@ -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
}```
8 changes: 7 additions & 1 deletion helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return mirr*100
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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 )
20 changes: 20 additions & 0 deletions tasks/Saving_Goal.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 7 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
number_of_periods: int

0 comments on commit 6f12cac

Please sign in to comment.