Skip to content

Instantly share code, notes, and snippets.

@marinho
Created August 12, 2015 00:47
Show Gist options
  • Save marinho/74e6986fa981ad166696 to your computer and use it in GitHub Desktop.
Save marinho/74e6986fa981ad166696 to your computer and use it in GitHub Desktop.
def calc_savings(years=10, monthly=500, rate=1.12, initial=0.):
"""
years = amount of years to saving money
monthly = amount saved per month (inflation is ignored)
rate = rate per year to apply. Must be 1 + annual interest rates
initial = initial amount to startup
"""
total = initial
for n in range(years):
total = (total + monthly * 12) * rate
print('Year #{}:\t{}'.format(n + 1, round(total, 2)))
return round(total, 2)
assert calc_savings(monthly=700, rate=1.12, initial=2000) == 171310.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment