Skip to content

Instantly share code, notes, and snippets.

@e0en
Created March 6, 2017 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e0en/9c2521f0072e75da7f9bc4898d57fda8 to your computer and use it in GitHub Desktop.
Save e0en/9c2521f0072e75da7f9bc4898d57fda8 to your computer and use it in GitHub Desktop.
How much money do I need to quit working?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def geometric_coeff(percentage, n):
if percentage != 0:
ratio = percentage / 100.0
return float((1 + ratio) ** n - 1) / ratio
else:
return n
if __name__ == '__main__':
years_to_live = int(input("Remaining lifespan in years: "))
yearly_interest = float(input("Yearly interest in percent: "))
yearly_inflation = float(input("Yearly inflation in percent: "))
yearly_spending = int(input("Yearly spending you want: "))
effective_interest = yearly_interest - yearly_inflation
# approximate for lifespan > 100
if years_to_live <= 100:
posession_coeff = geometric_coeff(effective_interest, years_to_live)
spending_coeff = geometric_coeff(yearly_inflation, years_to_live)
coeff_ratio = spending_coeff / posession_coeff
result = years_to_live * yearly_spending * coeff_ratio
print("You need " + str(result) + " to live without working")
else:
coeff_ratio = float(yearly_inflation) / effective_interest
result = years_to_live * yearly_spending * coeff_ratio
print("You need approx. " + str(result) + " to live without working")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment