There can be considerable variation in the output between Monte Carlo based retirement planners. This variation is generally a result of underlying assumptions that are often obscured deep in the code of the planner.
Although the Flexible Retirement Planner is not open source and the code is protected by copyright, because of the importance of openness in this discipline, selected sections of source code from the planner are posted below along with a discussion of how the internals of the planner work.
It’s understood that because only small parts of the code are being made public, a thorough analysis of the correctness or completeness of the program is impossible. On the other hand, the code snippets that have been selected are from the very heart of the planner.
In addition to pointers to source code, the following sections discuss some of the key implementation details in an effort to shed light on how the planner arrives at its results.
Generating Varying Simulation Input Data
At the heart of all Monte Carlo Simulations is a process for generating a sequence of inputs that can be used to determine likely outcomes for the problem being modeled . In the Flexible Retirement Planner, in addition to user provided constant inputs, there are two sequences that must be generated to run the simulation. These are the portfolio return sequence and the inflation sequence.
The benefits of including inflation as a varying factor in retirement planning simulations is debated and there’s a case to be made that it doesn’t help and may even hurt. The primary argument is that varying inflation without accounting for the correlation between inflation and other factors of the model is counterproductive. Because of this concern, inflation is not varied in the Flexible Retirement Planner by default. Under the default program settings, a constant inflation rate is used throughout all runs of the simulation in all years. The user does, however, have the ability to override this setting and may choose to assign a different value for inflation in different years. Users also may specify a non-zero standard deviation for inflation, which will cause the inflation rate to be stochastically varied in the simulation.
The next input sequence that the simulation depends on is the sequence of portfolio returns. The Flexible Retirement Planner departs from convention somewhat in how this sequence is modeled. Unlike many simulators that model the underlying asset mix of the user’s portfolio, including the cross-correlations between assets or at least asset classes, the Flexible Retirement Planner takes a more simplistic approach and only models the user’s overall portfolio returns. This means that the user need only provide a mean and a standard deviation to describe their expected portfolio returns over the life of their plan. The program does allow the user to enter different portfolio return parameters to cover different years of the plan, such as specifying a reduced portfolio return and volatility for the later years of a plan.
The simulation generates the input sequence of portfolio returns and inflation using a Gaussian pseudo-random number generator implemented through the MersenneTwisterFast algorithm. The source code for this algorithm can be found here.
Modeling only the overall portfolio rather than its components obviously simplifies the simulation and results in quicker execution, but some may argue that it oversimplifies the problem and renders the results unrealistic. The author differs with this view, believing instead that the simplification allows the underlying portfolio growth model to be simple, easily understood, and under the control of the user. The author also believes that using 10 to 20 years of imperfect cross-correlation data as an input to a 40 to 50 year forward projection introduces more noise to the result than information.
The Simulation Source Code
A code snippet (in Java) of the main simulation loop is provided here. In addition to the main loop of the simulation, this code also includes a handful of related methods referenced by the main loop. The simulation data structure that’s used throughout this main class that is not provided, however, the relevant contents can most likely be divined by reading through the code. If you have questions about the code, please don’t hesitate to ask using the email address below..
Another code snippet is provided for the decision rule logic that’s called from the main simulation loop. The code for these can be found here. These routines implement the Flexible and Conservative spending policies that are selectable by the user on the main input form.
The code doesn’t compile and it is incomplete. However, the code does serve to document that methodology used by the simulation. This code is published for the purpose of openness in the spirit of advancing the robustness of this and other retirement planning tools. Critical comments are welcomed, but it is requested that they be directed to info@flexibleRetirementPlanner.com before being published.
Number of Simulation Iterations & Resource Usage
The Flexible Retirement Planner is configured to run 10,000 simulation iterations when the “Run Simulation” button is pressed. This number is limited by compute-time and by the memory required to store the simulation results. Because of careful optimization of the Java code and because of tough choices about exactly what gets modeled in the simulation, the time required to run these 10,000 iterations is only a second or two on an average PC.
Much of the data that’s generated in each of the 10000 simulation runs is stored in the aggregate (as running totals that are later divided by the number of iterations). However, the yearly portfolio balance, the yearly withdrawal amount, and the yearly percent of expenses funded must all be stored on a per iteration basis so that median values for each can be displayed. The storage for these three values accounts for about half of the 50MB memory that’s used by the planner (8bytes per value x 100 years x 10,000 iterations x 3).