Created
March 6, 2017 01:44
-
-
Save e0en/9c2521f0072e75da7f9bc4898d57fda8 to your computer and use it in GitHub Desktop.
How much money do I need to quit working?
This file contains hidden or 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
#!/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