 |
Calculating compound interest.
Source code name: "finance2.py"
Programming language: Python
Topic: Finance/Compounding
DMelt Version 1. Last modified: 07/05/2015. License: Pro
https://datamelt.org/code/cache/finance2_5787.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from jhplot import *
principal=10000.0 # starting principal (initial investment)
rate=0.05 # percentage of interest rate
maxyear=50 # maximal years
c1=HPlot()
c1.visible(); c1.setAutoRange()
c1.setMarginLeft(100)
p1=P1D("Value $$")
p1.setDrawLine(1) # show as connected lines
for year in range( 1, 21 ):
amount = principal*(1.0+rate)**year
print "%4d%21.2f" % ( year, amount )
p1.add(year,amount)
c1.setNameX("year")
c1.setNameY("balance $$")
c1.draw(p1)
You see the box below because you did not login.