Become financially independent#
4% and 25 times rules#
Annual Spending |
Retirement Stash Needed |
---|---|
\(\$\)25,000 |
\(\$\)625,000 |
\(\$\)50,000 |
\(\$\)1,250,000 |
\(\$\)100,000 |
\(\$\)2,500,000 |
\(\$\)150,000 |
\(\$\)3,750,000 |
https://www.menti.com/alohp2v13yqh
Show code cell source
import pandas as pd
import ipywidgets as widgets
import matplotlib.ticker as mtick
from IPython.display import YouTubeVideo, display
Show code cell source
#retirement functions
def calc_stash_compound_interest(w, i, r, t):
return w + (i * (1+r) ** t + i * (1+r) * ((1+r) ** t - 1) / r)
def calc_principal(w, i, t):
return w + (i * t)
def get_retirement_df(rate, age, max_age, salary, spending, net_worth):
df = pd.DataFrame({'Age': pd.Series(range(age, max_age))})
df['Yearly Income'] = df.apply(lambda x: salary, axis=1)
df['Yearly Spending'] = df.apply(lambda x: spending, axis=1)
df['Yearly Savings'] = df.apply(lambda x: salary-spending, axis=1)
df['Total Stash'] = df.apply(lambda x: calc_stash_compound_interest(net_worth, salary-spending, rate*.01, x['Age']-age), axis=1)
df['Principal'] = df.apply(lambda x: calc_principal(net_worth, salary-spending, x['Age']-age), axis=1)
df['Total Stash'] = df['Total Stash'].astype('int64')
df['Principal'] = df['Principal'].astype('int64')
return df
style = {'description_width': 'initial'}
ma = 80
age = widgets.IntText(
value=20,
placeholder=20,
description='Age you begin investing:',
readout_format='d',
style=style,
disabled=False
)
rate = widgets.IntText(
value=4,
placeholder=4,
description='Rate of return on investments:',
readout_format='d',
style=style,
disabled=False
)
salary = widgets.IntText(
value=80000,
placeholder=80000,
description='Yearly Salary: $',
readout_format='d',
style=style,
disabled=False
)
spending = widgets.IntText(
value=60000,
placeholder=60000,
description='Yearly Spending: $',
readout_format='d',
style=style,
disabled=False
)
net_worth = widgets.IntText(
value=20000,
placeholder=20000,
description='Current amount of assets or debt: $',
readout_format='d',
style=style,
disabled=False
)
def r_output(r, a, sal, sp, w):
#create and display dataframe
def get_ret_age(df, ret_tgt):
try:
return df['Age'][df['Total Stash'] >= ret_tgt].iloc[0]
except:
return None
def get_ret_num(df, ret_age):
try:
return df['Total Stash'][df['Age'] >= ret_age].iloc[0]
except:
return df['Total Stash'].max()
def func(stash, retire_number):
if stash > retire_number:
return retire_number
else:
return stash
df_plot = get_retirement_df(r, a, ma, sal, sp, w)
ret_target = 25*sp
ret_age = get_ret_age(df_plot, ret_target)
ret_number = get_ret_num(df_plot, ret_age)
df_plot['Retired Stash'] = df_plot.apply(lambda x: func(x['Total Stash'], ret_number), axis=1)
if ret_age is None:
print("Try reducing your spending or you won't have enough money to retire.")
else:
ax = df_plot.plot.line(x='Age', y=['Total Stash', 'Retired Stash', 'Principal'], figsize=(12,8), linewidth=3, grid=True)
fmt = '${x:,.0f}'
tick = mtick.StrMethodFormatter(fmt)
ax.yaxis.set_major_formatter(tick)
ymin, ymax = ax.get_ylim()
xmin, xmax = ax.get_xlim()
ax.scatter(ret_age, ret_number, s=700, color='yellow', zorder=10)
ax.text(ret_age, ret_number+(ymax/100), s=' You may be able to retire at age ' + str(ret_age), fontsize='xx-large', fontweight='bold', color = 'purple', zorder=11)
#display(df_plot)
return("compare rate returns example")
Basic retirement planning tool#
Show code cell source
r_res = widgets.interactive(r_output, r=rate, a=age, sal=salary, sp=spending, w=net_worth)
widgets.VBox([r_res])
Takeaway#
Track your spending - budgeting
Payoff debts
Lower your spending
Build emergency fund
Invest for the future
Be nice to your future self
How soon can you retire?
The 4% rule
Invest early and often (more compound interest magic)
Links#
FIRE Intro on Youtube - https://www.youtube.com/watch?v=8si7cqw9wm0
FIRE retirement calculator - https://playingwithfire.co/retirementcalculator/
Mr. Money Mustache & the 4% Rule - https://www.mrmoneymustache.com/2012/05/29/how-much-do-i-need-for-retirement/
compound interest - https://www.fool.com/how-to-invest/thirteen-steps/step-1-change-your-life-with-one-calculation.aspx
Was the 401(k) a mistake? - https://www.nytimes.com/2024/05/20/podcasts/the-daily/401k-retirement.html
Citations#
Cumby, James & Degiacomi, Matteo & Erastova, Valentina & Guven, Jonna & Hobday, Claire & Mey, Antonia & Pollak, Hannah & Szabla, Rafał. (2023). Course Materials for an Introduction to Data-Driven Chemistry. Journal of Open Source Education. 6. 192. 10.21105/jose.00192.