Last active
September 11, 2018 20:01
-
-
Save davidvhill/ce50a3909a90aa53b4ca3091ae81761b to your computer and use it in GitHub Desktop.
Compound interest function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Compute compound interest given a rate, period and periodic rate increase | |
Args: | |
start: starting number | |
periods: compounding period | |
rate_growth: compounding rate growth rate | |
rate: starting compounding rate | |
Returns: | |
Final compounded value | |
""" | |
def compound(start, periods, rate_growth=.10, rate=.015): | |
t = start | |
r = rate | |
for x in range(periods): | |
t = t + (t * r) | |
r = r + (r * rate_growth) | |
return t | |
def table(start, period, rate, growth): | |
for x in range(period): | |
p2 = compound(start, x, rate=rate, rate_growth=growth) | |
p1 = compound(start, x - 1, rate=rate, rate_growth=growth) | |
yield {'year': x, 'total':p2, 'income':p2 - p1} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment