Retirement script
- Details
- Last Updated: Sunday, 31 March 2024 23:54
- Published: Tuesday, 03 December 2019 18:43
- Hits: 3431
This is a program written in C to calculate how long you can live off a certain amount of money that you have saved.
retire.c => It needs an input that speciifes the number of years you want to see the chart for. If you do not provide this number, the pgm errors out. Choose 100 as a starting number as 100 years is what we care about.
- Principal and Expense: Within the pgm, you can adjust the initial principal amount (I[0]) you want to start with (leave it at 100 currency units), the initial expense amount (E[0]) you want to start with (this can be adjusted based on how much of your savings go into paying all your bills for a year, 5 currency units is a reasonable number, implying you withdraw 5% out of your savings every year).
- Rate of Income/Expense: Next you can adjust the rate at which your principal grows (RateI, i.e rate of return on your savings) and the rate at which your expenses grow (RateE, i.e rate of inflation). If your money is invested in stock market, then you may choose rateI to be 5%, and rateE to be 5% too. Rational for rateI is that stock market returns would never be lower than nominal GDP growth, as that's the amount of money pumped into the system. On top of that, inflation rate would never exceed stock market return, as stock market is 90% owned by top 10% of the people, so bottom 90% will never make enough money via any investment to drive up inflation rate.
The pgm stops and prints the year when your expenses exceed your savings, basically meaning you will go bankrupt in year "X". If your rate of return on investment is much greater than rate of inflation, then you will never go bankrupt. This basically means you have not only freed yourself from slavery, but all your future generations to come. This is what we all want to achieve !!
Generate Data:
Pgm: retire.c
#include <stdio.h>
//#define NUM 100
main (int arg_cnt, char *arg_option[]) {
int NUM,NUM1;
//NUM = (int) arg_option[1]; //int cast of ascii returns wrong values
NUM = atoi (arg_option[1]);
NUM1 = (int)"";
//double I[NUM], E[NUM]; //I[n]=Principal in year n, E[n]=Expense in year n
double I[1000], E[1000]; //array size can't be dynamic, so fixing them at large values
int yr=0;
float RateI, RateE; //RateI=rate at which assets increase, RateE=Inflation rate
E[0]=1; //start with expense of 1 currency in 1st year
I[0]=100; //start with principal of 100 currency in 1st year
RateI=0.06; //expected income growth, 0.06=6% return on principal every year.change this to evaluate different cases
RateE=0.05; //expected expense growth,0.05=5% inflation rate, change this to evaluate different cases
FILE *fp;
int cnt;
for(cnt=0;cnt<arg_cnt;cnt++) {
printf("CNT=%d OPTION=%s NUM=%d \n", cnt,arg_option[cnt],NUM1);
}
//write data in file, nth year income and expense
fp = fopen("/home/kagrawal/scripts/retire.data", "w+");
if (fp == NULL)
{
printf("Error opening file!\n");
exit(-1);
}
printf("yr = %d, Income = %e Expense = %e \n",yr, I[yr], E[yr]);
fprintf(fp,"%d %e %e \n",yr, I[yr], E[yr]);
for(yr=1;yr<=NUM;yr++) {
E[yr] = E[yr-1]*(1+RateE); //E[n]=expense for year n
I[yr] = I[yr-1]*(1+RateI) - E[yr]; //I[n]=prinicpal left at end of year n after adding income and subtracting expenses
printf("yr = %d, Income = %e Expense = %e \n",yr, I[yr], E[yr]);
fprintf(fp,"%d %e %e \n",yr, I[yr], E[yr]);
if (I[yr] <= E[yr]) break; //If principal at end of year is less than the expenses for that year, then bankrupt !!
}
fclose(fp);
}
Compile:prompt> gcc retire.c => compiles retire.c and generates file a.out
Run: prompt> a.out 200 => This runs the pgm with total number of years set to 200. If bankruptcy happens before year=200, then pgm stops at that year.
Print Data:
retire.data => Next to plot the data, we dump out a file "retire.data", which can be used to plot data in gnuplot. It has 3 columns: year X, Total money left at end of year X, Total expenses for year X. This allows us to see how are net savings growing compared to our expenses.
Bring up gnuplot on any linux m/c, by typing "gnuplot" on the terminal.
prompt> gnuplot
gnuplot> plot retire.data => this plots data in points, not as lines
gnuplot> plot for [col=2:3] "retire.data" using col with lines => here we plot data for both col2 and col3 from retire.data using lines, so it's easier to see.
Sample output: In all exapmles below, I chose 5% inflation, as GDP growth (money creation) happens at rate of 5%/year, which I consider as inflation. The inflation number govt reports is a subset of real inflation, and doesn't apply in real life.
- 1. If we choose E[0]=5, I[0]=100, RateI=0.06 (i.e 6% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we go bankrupt in 22 years
- 2. If we choose E[0]=5, I[0]=100, RateI=0.10 (i.e 10% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we go bankrupt in 65 years
- 3. If we choose E[0]=5, I[0]=100, RateI=0.12 (i.e 12% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we never go bankrupt. Just an extra 2% return allowed us to achieve this. Since 12% is not a guaranteed return in US stock market, let's stick with 8% return, and see how much our expenses need to be as percentage of our savings, so that we can live forever.
- 4. If we choose E[0]=4, I[0]=100, RateI=0.08 (i.e 8% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we go bankrupt in 44 years.
- 5. If we choose E[0]=2, I[0]=100, RateI=0.08 (i.e 8% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we never go bankrupt. Just starting with a smaller expense base, allowed us to achieve this.
So, our target should be live off just the dividend returns of our investment. Since dividend returns are somewhere close to 2%, our expenses should be 2% of our net amount saved. At that point we can retire.
Conclusion:
The above plot shows that if we amass enough money where we ca live off dividends then we will never run out of money. Since dividends are about 2%, if we our expenses are < 2% of our wealth, we can be free from slavery. The assumption here is that inflation will never run higher than the stock market return. Because in worst case scenario, when everyone in US is invested in stock market, stock market will be the inflation driver. Or inflation rate will at most be stock market return.
Year 2010: If you amass $5M in savings, and invest all of that in USA stock market, 1.5% dividend will give you $75K/year. Federal taxes will take at most $10K (15%) out of this. Assuming you are able to live off $65K/yr as of 2010, you will be able to survive rest of your life without running out of money. Not only you, but your future generations too can be free of slavery.
So, cost to free one person from slavery in USA is $5M as of 2010. It goes up every year by the % amount the US stock market goes up by.
If you do similar maths for India, you will see that the cost to free one person from slavery in India is $1.5M (since cost of living in India is lot lower, $25K/year will easily suffice. Although dividends at 1% are lower than those in USA, but difference b/w stock market return and inflation is higher).
Year 2025: USA S&P500 index has gone up by 5X, while Nasdaq has gone up by > 10X. So, $5M from 2010 would have grown to $50M as of 2025. If you have $10M in savings as of 2025, and invest all of that in USA stock market, 1% dividend will give you $100K/year.Assuming 15% tax rate you will net $85K. You should be able to survive off $85K/year in 2025, if you were able to survive off $65K/year in 2010. So, you may still be free of slavery.