Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Created September 6, 2017 22:18
Show Gist options
  • Save shanemhansen/7bea9a8934625b5f715857de7c9a45b8 to your computer and use it in GitHub Desktop.
Save shanemhansen/7bea9a8934625b5f715857de7c9a45b8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
rate=0.07 # some interest rate 1==100% .07==7%
frequency=1/12.0 # yearly frequency
deposit_amount=200.0 # dollars
target=1000000 # dollars
current=100000 # dollars
def calcPeriod(rate,frequency,deposit_amount,target, current=0):
"""
Returns # of periods until target amount is acheived
"""
periods = 0
adj_rate = rate * frequency
while target > current:
periods += 1
# apply interest
current*=(1+adj_rate)
# apply deposit
current+=deposit_amount
return periods
periods = calcPeriod(rate,frequency, deposit_amount, target, current)
print "Your net worth will exceed %.2f after %d periods or %f years" % (target, periods, periods*frequency)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment