Skip to content

Instantly share code, notes, and snippets.

@davidvhill
Last active September 11, 2018 20:01
Show Gist options
  • Save davidvhill/ce50a3909a90aa53b4ca3091ae81761b to your computer and use it in GitHub Desktop.
Save davidvhill/ce50a3909a90aa53b4ca3091ae81761b to your computer and use it in GitHub Desktop.
Compound interest function
""" 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