my Retirement calculator (javascript) – can you retire now?

3 Apr 2019 | my Retirement calculator (javascript) – can you retire now? |

I decided to create a modern, easy to use and practical on-line retirement calculator, and I open-sourced it too!  There are ton’s of these available all over the internet, but none really quite had enough details or the specific details I wanted to make them useful.  So I approached this  retirement calculator from the FIRE ( Financially Independent Retire Early) perspective , where you’re goal is to save as much as possible , then after a certain number of years, you can retire and live off your savings and investments and misc. income.  I tried to take into account all the major factors affecting your earnings and expenses for the retirement years, incomes, savings, retirement, kids, housing, healthcare, taxes , inflation etc..

While this calculator is geared with the Fire philosophy, its still just a standard retirement calculator and can apply to virtually anyone. Yes, this is a USA-centric calculator, many of the assumptions and projections are based on living in the USA. Some other countries  may be close enough and the projects should still be good enough, but there’s a balance between a very generic calculator for the world and a very specific USA one I think I found a happy medium.

Of course no calculator can provide exact details as much of your input is projections plus  TAX, INFLATION  and other ECONOMIC conditions are complex and change over time. Nonetheless, you should be able to get a decent projection of how much you need to save and how much you can withdraw for a given period of time.   In a nutshell let this be a broad gauge to see if FIRE may work for you

The Calculator  – Try it out.

Click here to try out the retirement Calculator. The entire calculator runs in your’re web browser , all calculations and charts happen inside your web browser, There is no data sent to the server

Retirement Calculator

My Retirement Calculator

Calculation Model Methodology, technical bits (skip may be boring)

So the basic Calculation model works, very simply. I like simple things.

Essentially all your Income and SAVINGS are added up during the years, your working (working income) , and savings+retirement accounts  + other income over the course of your lifetime. Then these various forms of income are calculated against entered  Annual Percentage Yield to give your annual compound interest growth.  Here’s a sample of the calculation code for this section:

for (i = 1 ; i < years+1; i++) { 
  var ai = {} ;  //define a Income blank object
    var exp={} ; //define an Expense object
   //create an Annual Income object
  ai.i=(i);
  ai.age=(+i + +currentAge);


  ai.income_earned= ( i <= work_years  ) ? parseInt( $("#income").val()  ) : 0 ;
 	ai.income_saved = ( i <= work_years  ) ? $("#income").val()  * parseFloat( $("#income_savings_rate").val()/100 ) : 0 ; 
  
  ai.savings= parseFloat( $("#savings").val() ) ; 
  ai.savings_Int= +$("#savings").val()* parseFloat ( $("#savings_apy").val()/100 );
  ai.retirement=parseFloat(  $("#retirement").val() )  ; 
  ai.retirement_Int=  parseInt( $("#retirement").val() ) * parseFloat( $("#retirement_apy").val()/100 ) ;
  ai.one_time=(ai.age==inheritance_age) ? parseInt( $("#income_inheritance").val() ) : 0 ;
  ai.rents= parseFloat( $("#income_realestate_rentals").val() ) ;
  ai.pension=(ai.age>= ssn_year_eligible ) ? parseFloat(  $("#income_pension").val() ) : 0 ;
    ai.misc= parseFloat( $("#income_misc").val() ) ;
  ai.ssn= (  ai.age >= ssn_year_eligible ) ? parseFloat( $("#income_ss").val() ) : 0 ;

On the other side we have your EXPENSES . Expenses are more linear over your lifetime, income taxes are calculated based on 2018-2019 tax bracket, and applied to against your annual income.  Housing expenses have a term if you’re a home owner, with a separate field for perpetual costs like property taxes,  insurance, maintenance etc.  The number of dependents count as an expense, based on current pricing models of how much it costs to raise a child to 18. The other expense are pretty self-explanatory, adjust the default values  to better suit your particular circumstances.

Once we have all that information we  calculate your INCOME – EXPENSES we get a yearly surplus (or deficit), which we will apply to your SAVINGS, hopefully and this is the premise of this calculator.  You can work just long enough to grow your SAVINGS to the point where you can retire and only need to take a small percentage and live off that.  Sample Code:

// Now calculate SURPLUS OR DEFICIT for the year
  var diff=(incomes[i-1].total_annual_income.toFixed(2) - expenses[i-1].total_annual_expenses.toFixed(2) );
  // any money left over place in savings for that year.
          if ( i > 1 )
          incomes[i-1].savings =( incomes[i-1].savings + diff );

Finally we calculate what you’re withdrawal  rate is and how it will affect your savings over time after your retire. . The conventional wisdom of 4% withdrawal works out pretty well and is the default withdrawal rate. Adjusting this withdrawal rate. and the number of years you are working will have some of the largest impact as to what you can take out in retirement. Because you’ll have a larger nest egg at the beginning , your withdrawal percentage will likely yield a larger income than in your later years , which is why I display two retirement income values. Here’s a sample:

//Now calculate how much to withdraw from savings and retirement accounts AFTER we're RETIRED
 if (i > work_years) //now we're withdrawing
     {

   
     ai.retirement_income=(withdraw_rate*ai.savings) +  (withdraw_rate*ai.retirement  );	
     	
     	ai.savings = ai.savings-(withdraw_rate*ai.savings); //subtract % from savings 

     	//TODO: adjust retirement withdraw only after AGE 60 (USA time when no penalty)
     		ai.retirement= ai.retirement - (withdraw_rate*ai.retirement  ) ; //subract % from retirment investments
     
     //console.log(i+" > workyears+2 "+(+work_years+2)+" withdraw:"+withdraw_rate+ " on savings "+ai.savings);
			if ( (+work_years+1)==i )  //Show first and last year how much retirement income we get.
			 $("#retirement_income_start").text(formatUSD(ai.retirement_income));
     else
     $("#retirement_income_end").text(formatUSD(ai.retirement_income));	

     $("#retirement_savings_end").text(formatUSD(ai.savings));	
   

     }

There are a few one-time events, such as inheritance or sale (of a primary residence or business) which you choose how much and at what time point it occurs. Also Social Security you decide when to take it. If you have a pension , annual pension disbursements begin when social security begins.  Code for inheritance looks like this.

ai.one_time=(ai.age==inheritance_age) ? parseInt( $("#income_inheritance").val() ) : 0 ;

Assumptions and Simplifications

Obviously it’s not possible to model your complete financial life down to every detail or for that matter even the larger economy in a JavaScript web  page app. So I made lots of assumptions and simplifications to the model .  I choose these simplifications because many of them may not apply to most folks, and some are very dependent on your particular life circumstances, while others would have over-complicated the model yet only have minimal impact 0n the final numbers.  Here are a few of the simplifications ans assumptions I made.

  • This is a USA- centric  retirement calculator. If you live in another part of the work, your income taxes , social security ,  inflation rates, currency exchange rates (relative to USD) ,healthcare,  interest rates, and other economic/legally conditions will all be different. So if you really want this calculator for your particular region and you know a little web programming (or know someone who does) you can have them modify the code to meet your requirements.
  • Surplus income applied to savings: I applied all annual surplus or deficits to your savings only , not retirement accounts, again for simplification purposes, a more complete model may split-the income gained between savings and retirement, but applying it to the less APY earning  is a more conservative approach, plus it also simplifies tax accounting issues (10% penalty before 59.5 years in the US )  with early withdrawals of retirement accounts.
  • Interest calculations compound annually: I assumed interest calculations are compounded annually, again, to simplify the model and daily vs. weekly vs. annual compound interest generally are insignificant in terms of income.
  • Married (household): I assume the income and expense numbers are for a household, so a single income-earner or married income earners, are both contributing to the income, so single or married does not affect expense, this may or may not be true but is situation dependent.
  • Early Retirement Withdraws: There are two buckets for savings, and retirement accounts and  savings  accounts this was mostly done to have short-term savings and long-term savings rates with different APY.  When computing withdrawal rates of say 4% it is applied equally to Savings and Retirement to give you what you can get from your combined accounts. I also did not take into account thee 59.5 age rule for non-penalty retirement withdraws, again to simply calculations.
  • Required Minimal Disbursements (RMB): in the US you need to begin withdrawing from most retirements accounts by age 70, there’s a calculation as to what your RMD is . I neglected this to simplify retirement withdrawal calculations and a precise calculation for this would be complex and very much based on you particular circumstances on an account by account level.
  • Kids college tuition, was not included because; not everyone has kids, not all kids go to college and those that do may get a blend of scholarships , grants , military reimbursement etc. to help defer their costs. As an approximation , you can simply add a portion of what  you want to save for there collegiate   education to your annual discretionary expense .
  • Medicare insurance / Long Term Care: I simplified the healthcare expense as a static annual recurring cost for your entire lifetime. For most Americans (there goes that USA centric thing again) at age 65 you’re eligible for Medicare health insurance. Again consider this as a conservative approach and you can always put those unused Healthcare expenses into HealthCare Savings Account. or also apply these on-going healthcare costs towards LTC insurance, to help defer possible long-term care costs .
  • Inflation: I applied the inflation rate to the sum of all the expenses , inflation percentage is based off CPI.
  • Tax Brackets: I used  a simple , married filing jointly tax brackets, again modeling the entire tax code and all its variables is not practical . But this is a conservative approach as it  over-estimates tax due  for singles.
  • Estate Planning: This is a complex topic and not practical to model in a retirement calculator. But if the calculator show a large nestegg (> $1.5mln) consider estate planning.
  • Food, Utilities, Energy Expense: I used some common defaults based on government or other agency statistics, adjust  them to suit your situation.
  • Debt: I had forgotten about this one, but not I added a Debt column and payoff years, to better help model it for those folks that have incurred large amounts of student debt or car loans or any other kind of debt (except mortgage, that has its own field).

Yes,, there’s probably still  few more simplifications, but again this is necessary otherwise the calculator would become extremely complicated and not practical for a the back-of-the-envelope calculation-of when you could retire

Life is not linear, and many things can happen over a lifetime to  throw all these projections in the toilet. Situations such  recessions, job loss, divorce,  health crisis, disability, tax changes, unexpected inheritance, etc.. all will greatly affect your retirement plans especially the earlier they happen in your life. Again its not possible to account for all this.

Requests for changes and enhancements

This is an open-sourced calculator, feel free to grab the code yourself, or propose any changes or enhancements over at my GitHub Repository.

Technical Stuff and Open Source

This calculator runs entirely in your’re web browser, its uses the following web technologies. Keeping it simple , yet at the same time modern looking and attractive.

I choose to keep the technologies as  simple as possible. I’m aware some techies and web developers may pooh-pooh these simplistic technologies, and why didn’t I write this in Angular or React or Vue (btw I would have chosen VUE.js) ?, but my rationale was that because I wanted to make this as accessible and easily modifiable by other folks, I wanted to give the broadest possible access to anyone , even those who aren’t super-technical can just go to my Github clone the page, and begin making edits to the calculation model easy peasy..

I also used external CDN links to the above supporting libraries, and keep the entire code in one index.html page, again trying to keep everything self-contained and compact. You can of course download the supporting libraries if you need to run this completely off-line. Anyways for more  technical details and conversation head over to my GitHub repository. This uses a BSD-License, pretty much is free to use permissive license, simply give credit and link  back to the original author..

Conclusion

As mentioned earlier, my inspiration for this project, was the FIRE movement, and the notion that if you start early enough , live on much less than you make, and save for tomorrow, you may actually escape the rat race a lot earlier than you expect, and enjoy life the real golden years of your life with family and friends. Remember no one ever says on their deathbed, “Boy I wish I had  worked longer in my cubicle farm, “. So this is may small contribution  to help  use run those numbers with a few key details, and I think this is a decent start. Let me know..

[poll id=”2”]

2 thoughts on “my Retirement calculator (javascript) – can you retire now?

  1. Reply Jennifer J Apr 9,2019 10:29 am

    I don’t understand the retirement vs. savings, if you’re only adding surplus income to savings how does the retirement grow..

    • Reply Tony B. Apr 30,2019 3:05 pm

      As I mentioned this is a trade off to make the calculation code simpler. To do it more precisely, it would require additional fields to have you determine what % should go into savings/ retirement, additionally things get more complicated when you get to age 70.5 due to legal requirements or Minimum Disbursement. So by throwing everything into taxable savings account, I’m err’rring on the conservative (less APR yielding) side, while keeping the tax implication considerations to a minimum. In short,this model will provide a lower income estimate than what you might actually get.

Leave a Reply