index all rss twitter github linkedin email

Álvaro Ramírez

14 April 2019 Compound interest calculations

Saving Tony Bedford's python snippets for calculating compound interest. Really just an excuse to fire up Emacs and play with org babel.

t = 20 # years
r = 0.07 # rate
pv = 200000.00 # present value
fv = pv * (1+r)**t # future value
print("Pension of %.2f at %d%% will be worth %.2f in %d years" % (pv, 100 * r, fv, t))
Pension of 200000.00 at 7% will be worth 773936.89 in 20 years
t = 20 # years
r = 0.07 # rate
pv = 200000.00 # present value
n = 1
fv = pv * (1 + r/n)**(n*t) # future value
print ("First formula calculates final value to: %.2f" % fv)

fv = pv * (1 + r/n)**(n*1) # year 1 only
print("Year %d: %.2f" % (1, fv))
for i in range (2, t+1):
    fv = fv * (1 + r/n)**(n*1) # Calculate one year at a time
    print("Year %d: %.2f" % (i, fv))
First formula calculates final value to: 773936.89
Year 1: 214000.00
Year 2: 228980.00
Year 3: 245008.60
Year 4: 262159.20
Year 5: 280510.35
Year 6: 300146.07
Year 7: 321156.30
Year 8: 343637.24
Year 9: 367691.84
Year 10: 393430.27
Year 11: 420970.39
Year 12: 450438.32
Year 13: 481969.00
Year 14: 515706.83
Year 15: 551806.31
Year 16: 590432.75
Year 17: 631763.04
Year 18: 675986.46
Year 19: 723305.51
Year 20: 773936.89