In [1]:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd

This is a quick and dirty function for calculating compound interest

In [2]:
# Python3 program to find compound 
# interest for given values. 

def compound_interest(principle, rate, years, monthly_cont, num_months): 
    """
    principle = the amount of money that you begin with
    rate = the PERCENTAGE OF INTEREST (0-100) that you earn each time
    years = the number of times you will gain interest (years)
    monthly_contr = the amount you plan to input every month
    num_months = number of months of contributions
    """

    amount = principle
    yearly_contr = monthly_cont * num_months
    indiv_amounts = []

    # Calculates compound interest 
    for ii in range(years):
        amount += yearly_contr                                                     # Add a single years total contributions
        year_interest = amount * (rate/100)                                        # Calculate the interest on the new amount
        amount += year_interest                                                    # Add the interest
        indiv_amounts.append(amount)                                               # Collect the yearly amounts for later plotting
    total_cmp_int = amount - (principle + (monthly_cont * num_months * years))     # Calculate the total compound interest by subtracting the principle and total contributions
    
    # Print info.
    print("Compound interest = ${:,.2f}".format(total_cmp_int))
    print("Total after {} years = ${:,.2f}".format(years,amount))
    
    # return the final amount and individual amounts after each year
    return amount, indiv_amounts

If we assume that we want to try and utilize IU's 457b retirement plan resource, how might this affect our retirement?

Calculate the first 5 years of PhD contributions and compound interest, assuming you can contribute $200 a month, and you make approximately 5% intrest

In [3]:
# First 5 years in PhD
total_value, yearlys = compound_interest(principle = 1,
                              rate = 5,
                              years = 5,
                              monthly_cont = 200,
                              num_months = 10) # We don't get paid over the summer
Compound interest = $1,604.10
Total after 5 years = $11,605.10

Assuming that you make zero contributions for the rest of your life after you Ph.D., we calculate the interest on the total after 5 years - for 30 more years (estimated retirement date).

In [4]:
total, yearlys2 =compound_interest(principle = total_value,
                              rate = 5,
                              years = 30,
                              monthly_cont = 0,
                              num_months = 12) 
Compound interest = $38,551.48
Total after 30 years = $50,156.58

The function outputs a list of each value at the end of each year, I put them together here

In [5]:
# Combine the yearly amounts into one list
all_yearlys = yearlys + yearlys2

Create a dataframe for easier plotting

In [6]:
# Create a dataframe with years and values
yearly_values = pd.DataFrame({"Years" : np.arange(1,len(all_yearlys)+1,1),
                              "Value" : all_yearlys
                             })
In [7]:
yearly_values.head()
Out[7]:
Years Value
0 1 2101.050000
1 2 4306.102500
2 3 6621.407625
3 4 9052.478006
4 5 11605.101907

Show how your money grows over time.

In [8]:
import matplotlib as mpl
plt.figure(figsize=(15,7))

ax = sns.lineplot(data = yearly_values,
                  x = "Years", 
                  y = "Value",
                  markers = "o", 
                  size=100)

plt.vlines(x = 5,
           ymax=20000, 
           ymin=0, 
           linestyles="--")

plt.title('Total = ${:20,.2f}'.format(yearly_values.iloc[-1]["Value"]))

plt.annotate(s = "Stop Contributions.", 
             xy = (5,20000))

formatter = mpl.ticker.FormatStrFormatter('$%1.2f')
ax.yaxis.set_major_formatter(formatter)
plt.grid()
sns.despine()

Now, lets assume that we're normal people and we keep making money and we keep putting that money into our account overtime - which also continues to generate compound interest.

  • Here, we calculate compound interest for contributing $200 every month for the next 35 years (5 Ph.D. years + 30 more, like last time)
In [9]:
# First 5 years in PhD
total_value, yearlys = compound_interest(principle = 1,
                              rate = 5,
                              years = 5,
                              monthly_cont = 200,
                              num_months = 10) # We don't get paid over the summer


# 200 for 30 more years
total_value, yearlys2 = compound_interest(principle = total_value,
                              rate = 5,
                              years = 30,
                              monthly_cont = 200,
                              num_months = 12) # Now we do get paid over the summer

all_yearlys = yearlys + yearlys2


# Create a dataframe with years and values
yearly_values = pd.DataFrame({"Years" : np.arange(1,len(all_yearlys)+1,1),
                              "Value" : all_yearlys
                             })
Compound interest = $1,604.10
Total after 5 years = $11,605.10
Compound interest = $133,977.38
Total after 30 years = $217,582.48

We can see that the total value of our investment grows a lot from the original $50k

Lets plot the growth over time

In [10]:
plt.figure(figsize=(15,7))

ax = sns.lineplot(data = yearly_values,
                  x = "Years", 
                  y = "Value",
                  markers = "o", 
                  size=100, legend=False)

plt.vlines(x = 5,
           ymax=50000, 
           ymin=0, 
           linestyles="--")

plt.annotate(s = "End of Ph.D.", 
             xy = (5,50000))

plt.title('Total = ${:20,.2f}'.format(total_value))

formatter = mpl.ticker.FormatStrFormatter('$%1.2f')
ax.yaxis.set_major_formatter(formatter)

plt.grid()
sns.despine()

Now lets see what happens if, like a REAL regular person, we graduate and start making more money, so we can contribute more to our retirement!

First, lets calculate the 5 years during Ph.D.

In [11]:
# First 5 years in PhD
total_value, yearlys = compound_interest(principle = 1,
                              rate = 5,
                              years = 5,
                              monthly_cont = 200,
                              num_months = 10) 
Compound interest = $1,604.10
Total after 5 years = $11,605.10

Assuming you get a data science job after you graduate, the average base salary in the US = 122K

But lets be cautious and assume that we make around $100K for the rest of our lives

In [12]:
# 100k / 12 months --> REMEMBER THESE ARE PRETAX CONTRIBUTIONS, SO WE DON'T NEED TO REMOVE INCOME TAX
monthly_payment = 100000 / 12
monthly_payment * .1
Out[12]:
833.3333333333335

So if we put in 10% of our salaray (you can put in up to 15%) into our retirement, thats a little over $800. Lets round down to a clean 800.

Now I calculate the next thirty years, building on the first five we just calculated...

In [13]:
total, yearlys2 =compound_interest(principle = total_value,
                              rate = 5,
                              years = 30,
                              monthly_cont = 800,
                              num_months = 12) # paid each month 
Compound interest = $420,255.06
Total after 30 years = $719,860.16

Combine the first five and last thirty years...

In [14]:
# Combine the yearly amounts into one list
all_yearlys = yearlys + yearlys2
In [15]:
# Create a dataframe with years and values
yearly_values = pd.DataFrame({"Years" : np.arange(1,len(all_yearlys)+1,1),
                              "Value" : all_yearlys
                             })
In [16]:
yearly_values.head()
Out[16]:
Years Value
0 1 2101.050000
1 2 4306.102500
2 3 6621.407625
3 4 9052.478006
4 5 11605.101907

And what this looks like now is...

You have more than $700k.

In [17]:
import matplotlib as mpl
plt.figure(figsize=(15,7))

ax = sns.lineplot(data = yearly_values,
                  x = "Years", 
                  y = "Value",
                  markers = "o", 
                  size=100, legend=False)

plt.vlines(x = 5,
           ymax=50000, 
           ymin=0, 
           linestyles="--")

plt.annotate(s = "End of Ph.D.", 
             xy = (5,50000))

plt.title('Total = ${:20,.2f}'.format(total))

formatter = mpl.ticker.FormatStrFormatter('$%1.2f')
ax.yaxis.set_major_formatter(formatter)

plt.grid()
sns.despine()

This was a relatively conservative estimation of the kind of money you can make by simply putting some money into an account and completely forgetting about it. All you have to do is make the conscious effort to go through the process of setting this up. Once you decide to contribute some percentage of your income, you will forget that you were going to have that money in your pocket because life is too hectic.

Not everyone is going to be able to create a business that makes them rich. This is how average people accumulate wealth and, fortunately, it's extremely easy. Start as early as possible and stay consistent.

In [ ]:
s