Plotting Compound Interest
Let’s graphically investigate the effect of compounding. What if we invest \$100 into an investment or bank account that guarantees us 5% annual return over 30 years? What will our investment look like over time? The first step is to create a list to denote each year.
In [6]:
#Create a list to denote each year
years = list(range(31))
print(years)
Now, we can make a list to denote the value at each point in time.
In [7]:
p = 100
r = .05
A = [compoundInterest(p,r,t) for t in years]
print(A)
Finally, graph the values, and notice how the slope gets larger and larger!
In [8]:
import matplotlib.pyplot as plt
plt.plot(years,A)
plt.xlabel("Year")
plt.ylabel("Value")
plt.title("Compound Interest")
plt.show()