'How could I find the value of an account at a certain date using compounding interest?
So I have an account that provides a 2.02% annual return plus rf%, which is just the annual deposit rate given in this list below. I first made the principle deposit of $2500 in July 2018 at 11:59pm. On the last day of every month I make an additional $800 deposit, ex: on August 31 '18 at 11:59pm I deposit $800 and so on. The list starts from August' 18 till Jan'22.
rate = [1.91, 1.95, 2.19, 2.20, 2.27, 2.40, 2.40, 2.41, 2.42, 2.39, 2.38, 2.40, 2.13, 2.04, 1.83, 1.55, 1.55, 1.55, 1.58, 0.65, 0.05, 0.05, 0.08, 0.09, 0.10, 0.09, 0.09, 0.09, 0.09, 0.09, 0.08, 0.07, 0.07, 0.06, 0.08, 0.10, 0.09, 0.08, 0.08, 0.08, 0.08, 0.08]
The code I have created is very simplistic in nature and when i run it doesn't give me the exact number up to two decimal points as I want. I also want to implement the list of rates I have to correspond to the months I want to know the amount. In this case it's Ocotober '18 which it's rate is 2.19, and for Feb'22 it's 0.08.
P =int(2500)
r =1.91
r2=0.08
FV1= P*(1+(r+2.02)//(100//12))+800
FV2= P*(1+(r2+2.02)//(100//12))+800
print("The value of my account on September 1st 2018, 00:00 am is",FV1)
print("The value of my account on February 1st 2022, 00:00 am is",FV2)
For example, if all goes well for september '18 the value should be; 2500*(1+(1.91+2.02)/100/12)+800 = 3308.19.
Solution 1:[1]
I'm not sure your equation is right. It's been a while since I looked at the compounding interest formula, but if I were you that's where I'd start.
Alternatively, I'd iteratively calculate the interest for each month and add it to the principal for the next month, since your rate of interest is changing
# These two imports just to add one month to print nice output
import datetime
from dateutil.relativedelta import relativedelta
bonus_rates = [1.91, 1.95, 2.19, 2.20, 2.27, 2.40, 2.40, 2.41, 2.42, 2.39, 2.38, 2.40, 2.13, 2.04, 1.83, 1.55, 1.55, 1.55, 1.58, 0.65, 0.05, 0.05, 0.08, 0.09, 0.10, 0.09, 0.09, 0.09, 0.09, 0.09, 0.08, 0.07, 0.07, 0.06, 0.08, 0.10, 0.09, 0.08, 0.08, 0.08, 0.08, 0.08]
base_rate = 2.02
monthly_deposit = 800
principal = 2500
current_date = datetime.date(2018, 7, 31)
acct_values = []
for month_bonus_rate in bonus_rates:
current_date += relativedelta(months=1) # Increment the month
r = (base_rate + month_bonus_rate) / 12 # The rate for this month
i = principal * r / 100 # The interest for this month
principal += (i + monthly_deposit) # Add interest and monthly deposit to new principal
acct_values.append(principal)
print(f"At the end of {current_date.strftime('%Y-%m')}, account value = {principal:.2f}")
Which gives the output:
At the end of 2018-08, account value = 3308.19
At the end of 2018-09, account value = 4119.13
At the end of 2018-10, account value = 4933.58
At the end of 2018-11, account value = 5750.93
...
At the end of 2021-09, account value = 34401.70
At the end of 2021-10, account value = 35261.90
At the end of 2021-11, account value = 36123.61
At the end of 2021-12, account value = 36986.82
At the end of 2022-01, account value = 37851.55
The acct_values list is:
[3308.1875,
4119.132086979167,
4933.583375384319,
5750.933143587754,
6571.49272957608,
...
35261.898333886056,
36123.606655970354,
36986.822967618304,
37851.54990781163]
As you can see, the value of your account on September 1 is calculated correctly as 3308.1875 (or .19 when rounded to two places)
You can access the elements of the list to get the values for any of the months.
Note that using floating-point numbers for counting money has some inherent problems that you should be aware of.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
