Skip to content
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
5 changes: 5 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ The initial price of the product or service. |
| | | - `interest_rate` (float): The annual interest rate on the savings. |
| | | - `goal_amount ` (float): The desired savings goal amount. |
|-----------------------------|----------------------------------------|----------------------------------------------------------------------|
| GET /fd_payout | Calculate fd payout monthly vs yearly vs cumulative | - `p` (int): principal |
| | | - `t` (int): term in years |
| | | - `r` (float): rate in decimals |
| | | - `c` (int): number of months after which to compund |
|-----------------------------|----------------------------------------|----------------------------------------------------------------------|
24 changes: 24 additions & 0 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2306,3 +2306,27 @@ Sample Output
"total_contributions": 3600,
"interest_earned": 315.27777777777777
}```

```

**POST** `/fd_payout`
- Request body : `p`,
`t`,
`r`,
`c`,

- Sample output
```py
{
{
"Tag": "fd_payout",
"Principal": 1000,
"Term (in years)": 2,
"Rate (as a decimal)" : 0.04,
"Compounding period" : 6,
"Payout_monthly": 80,
"Payout_yearly": 81,
"Payout_cumulative": 82,
}
}
```
10 changes: 10 additions & 0 deletions helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,3 +2068,13 @@ def calculate_modified_internal_rate_of_return(ending_cash_flow: float,
number_of_periods: int):
mirr = ((ending_cash_flow / initial_cash_flow) ** (1 / number_of_periods)) - 1
return mirr*100

# Function to calculate fixed deposit payout for monthly, yearly, cumulative based on given compounding period
def fd_payout(p : float, t : int, r : float, c : int) -> list[int]:
c = 12//c
interest_monthly = p * t * r
amount_yearly = p * ((1 + r/c)**c)
interest_yearly = (amount_yearly - p) * t
amount_cumulative = p * ((1 + r/c)**(c * t))
interest_cumulative = amount_cumulative - p
return [round(interest_monthly), round(interest_yearly), round(interest_cumulative)]
14 changes: 14 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,3 +1996,17 @@ def saving_goal(request: SavingGoal):
request.monthly_contributions ,
request.interest_rate,
request.goal_amount )


# Endpoint for function fd_payout

@app.post(
"/fd_payout",
tags=["fd_payout"],
description="Calculate monthly, yearly and cumulative fixed deposit payout",
)
def fd_payout(
request: FdPayout
):
return fd_payout(request.p, request.t, request.r, request.c)

25 changes: 25 additions & 0 deletions tasks/fd_payout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def fd_payout(
p : float, t : int, r : float, c : int
):

'''
Calculate fixed deposit
Inputs: principal, term in years, rate as a decimal, compunding period(compund after how many months)
Ouput: fixed deposit payout for monthly, yearly and cumulative compounding
'''
try:
payout = functions.fd_payout(
p, t, r, c
)
return {
"Tag": "fd_payout",
"Principal": p,
"Term (in years)": t,
"Rate (as a decimal)" : r,
"Compounding period" : c,
"Payout_monthly": payout[0],
"Payout_yearly": payout[1],
"Payout_cumulative": payout[2],
}
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 @@ -659,3 +659,9 @@ class ModifiedInternalRateOfReturn(BaseModel):
ending_cash_flow: float
initial_cash_flow: float
number_of_periods: int

class FdPayout(BaseModel):
p : int
t : int
r : float
c : int