**UPDATE: I was not careful enough when I wrote this post initially and while the concepts were right there were some non-trivial errors. This article was corrected 2018-08-07.**

Below is a program encoding a very simple financial model. I'm starting to assuming the 4 percent rule... this is the theory that you can take 4% of your investments out ever year and you should never run out of money, even in a volatile stock market. It's well documented elsewhere so I won't get in to great detail here, but take a look at this https://www.investopedia.com/terms/f/four-percent-rule.asp. For our purposes suffice to say that this is a pretty conservative rule.

- "income" is your current income.
- "save" is your savings rate... that is, what fraction of your income you put in to savings.
- "growth" is assumed average growth of your investments. 8% is a fairly common number. Add in 2% inflation and call it 6%.
- "years" is the number of years worked until retirement.

- The amount you now have in investments
- The income you were living on pre-retirement
- The income you were living on post-retirement

So, lets say we have a theoretical person who makes 100k a year, and saves 10% of their money every year... how many years will it take for them to retire?

Here's the basic program with the input values elided...

Here's the basic program with the input values elided...

sum=0

for x in xrange(0,years):

sum*=1+growth

sum+=income*save

print "income", income

print "save", save

print "growth", growth

print "years", years

print "saved", sum

print "living pre returnment", income*(1-save)

print "living post retirement", sum*0.04

So we pump those numbers in and we get

save 0.1

growth 0.06

years 47

saved 2410986.12095

living pre returnment 90000.0

living post retirement 96439.4448381

This means that our hypothetical person could retire after working for 47 years.

So, what if they saved 20%?

income 100000

save 0.2

growth 0.06

years 34

saved 2083675.09192

living pre returnment 80000.0

living post retirement 83347.0036769

So, what if they saved 20%?

income 100000

save 0.2

growth 0.06

years 34

saved 2083675.09192

living pre returnment 80000.0

living post retirement 83347.0036769

So, they get to retire in 34 years. If you're wondering how I got 35, I just tried values until I got post retirement to come out just over pre-retirement.

So, lets do it again How about 50%?

income 100000

save 0.5

growth 0.06

years 16

saved 1283626.4039

living pre returnment 50000.0

living post retirement 51345.0561562

16 years. Alright, one more. How about 75%? save=0.75

income 100000

save 0.75

growth 0.06

years 7

saved 629537.823739

living pre returnment 25000.0

living post retirement 25181.5129496

So 7 years. Alright, so what's really going on here? There are a bunch of really interesting properties. First of all, this math works out the same no matter how much you make. The number of years it takes to retire is the same regardless of how much money you make, it's only your savings rate that matters. The reason for this is that people want to retire at the same standard of living as when they were working. So, someone who saved 25% of 200k is living a little larger than someone who saved 25% of 50k.

So, lets do it again How about 50%?

income 100000

save 0.5

growth 0.06

years 16

saved 1283626.4039

living pre returnment 50000.0

living post retirement 51345.0561562

income 100000

save 0.75

growth 0.06

years 7

saved 629537.823739

living pre returnment 25000.0

living post retirement 25181.5129496

So 7 years. Alright, so what's really going on here? There are a bunch of really interesting properties. First of all, this math works out the same no matter how much you make. The number of years it takes to retire is the same regardless of how much money you make, it's only your savings rate that matters. The reason for this is that people want to retire at the same standard of living as when they were working. So, someone who saved 25% of 200k is living a little larger than someone who saved 25% of 50k.

Obviously if you are barely making enough to live on saving 75% of it is really hard. I'm not trying to get political here, or claim anyone can retire bla bla. I'm just trying help people understand the math.

This makes basically means the secret to retirement isn't just living below your means, but well below your means. You don't only get to save more of your money, but if you can be comfortable at a lower standard of living, you don't *need* as much, this means you need less money while saving more.

Now, all of this is a cute mathematical model... but lets say you *actually* want to retire. There are 2 extra factors I just want to mention.

First of all, most people actually spend slightly less in retirement than they did before retirement. We assume above that your going to retire at the same level of comfort and thus the same level of spending, but lets say you just want to go hang out in thailand? That's a lot cheaper.

Second of all, the 4% rule, while being really good for early retirement, is quite conservative. If you're thinking of retiring early, there's always the option of making a little income again if needed. For those who are older it's *okay* to use up all your money eventually, since people do eventually die. I haven't studied models for the latter case much.

Obviously, I'm no financial advisor... just a computer nerd, so take all of this with a grain of salt :).