Simulations
The simulations estimate the market returns for the duration of a client's life.
The simulated results are based on the client's portfolio estimates for average returns, best case scenario and worst case scenario over the years. The results of the simulations are sequences of yearly returns that best track those scenarios.
Those results are then applied on top of the client's assets for every given year, generating thus a dollar amount ROI every year, which are displayed in the Cashflow table and in the returns graph.
Algorithm​
The algorithm for the simulations is as follows:
- Determine the duration of the client's cashflow calculations.
- (i.e. from Start Date to the last age where there's a transaction).
- Find the average returns
- Find the maximum returns
- Find the minimum returns
Finding the average returns​
- For each year, assign a random % return value. The list of all such values over the years is called a
candidate.- These values are calculated following a normal distribution based on the 1-year return estimates from the client's portfolio.
- The first
candidateis automatically selected as thechosen- the final list of values that will be applied over the client's data.
- Evaluate the
candidateagainst the portfolio's timeframe estimates (1y, 5y, 10y etc).- The
candidate's yearly values are compounded to calculate the expected returns for every timeframe. - The absolute difference between the calculated value and the estimated value for each timeframe is called
error.
- The
- Evaluate the
candidateagainst the currentchosen.- If the resulting
erroris less than thechosen'serror, that means the newcandidatebetter tracks the client's portfolio, therefore it is made the newchosen. - Otherwise, discard this
candidate.
- If the resulting
- Repeat steps 1 - 4 until the one of these conditions is met:
- The
erroris less than a pre-defined tolerance margin (e.g. 0.5%). - 1,000,000
candidateshave been tried.
- The
- When it ends, the list of values called
chosenis guaranteed to be the best representation of the client's portfolio we could find.
Finding the maximum returns (best case scenario)​
The process is identical to finding the average returns, with the exception of generating new candidates (step 1), described as follows:
- For each year, assign a random % return value. The list of all such values is called a
candidate.- Values are based on the average scenario's
chosenvalues. Let's call itchosen avgfor brevity. - Each value must be greater than or equal to the
chosen avgfor that same year. - Each value must be less than or equal to the client's portfolio
max returnvalue for the timeframe that most closely matches that year.- Except when the
chosen avgis greater thanmax return, in which case the value is strictly equal tochosen avg.
- Except when the
- E.g. For a simulation starting in 2022, if
chosen avgfor the year 2032 is 5.3% and the 10ymax returnestimate is 8.5%, that year'smaxis a random number between 5.3% and 8.5%.
- Values are based on the average scenario's
Finding the minimum returns (worst case scenario)​
The process is identical to finding the average returns, with the exception of generating new candidates (step 1), described as follows:
- For each year, assign a random % return value. The list of all such values is called a
candidate.- Values are based on the average scenario's
chosenvalues. Let's call itchosen avgfor brevity. - Each value must be less than or equal to the
chosen avgfor that same year. - Each value must be greater than or equal to the client's portfolio
min returnvalue for the timeframe that most closely matches that year.- Except when the
chosen avgis less thanmin return, in which case the value is strictly equal tochosen avg.
- Except when the
- E.g. For a simulation starting in 2022, if the
chosen avgfor the year 2032 is 5.3% and the 10ymin returnestimate is 1.5%, that year'sminis a random number between 1.5% and 5.3%.
- Values are based on the average scenario's
Code​
The source code can be found at src/calc/returns/generateRandomReturns.ts (requires access to the github repository).