Skip to main content

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:

  1. Determine the duration of the client's cashflow calculations.
    • (i.e. from Start Date to the last age where there's a transaction).
  2. Find the average returns
  3. Find the maximum returns
  4. Find the minimum returns

Finding the average returns​

  1. 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 candidate is automatically selected as the chosen - the final list of values that will be applied over the client's data.
  2. Evaluate the candidate against 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.
  3. Evaluate the candidate against the current chosen.
    • If the resulting error is less than the chosen's error, that means the new candidate better tracks the client's portfolio, therefore it is made the new chosen.
    • Otherwise, discard this candidate.
  4. Repeat steps 1 - 4 until the one of these conditions is met:
    • The error is less than a pre-defined tolerance margin (e.g. 0.5%).
    • 1,000,000 candidates have been tried.
  5. When it ends, the list of values called chosen is 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:

  1. 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 chosen values. Let's call it chosen avg for brevity.
    • Each value must be greater than or equal to the chosen avg for that same year.
    • Each value must be less than or equal to the client's portfolio max return value for the timeframe that most closely matches that year.
      • Except when the chosen avg is greater than max return, in which case the value is strictly equal to chosen avg.
    • E.g. For a simulation starting in 2022, if chosen avg for the year 2032 is 5.3% and the 10y max return estimate is 8.5%, that year's max is a random number between 5.3% and 8.5%.

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:

  1. 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 chosen values. Let's call it chosen avg for brevity.
    • Each value must be less than or equal to the chosen avg for that same year.
    • Each value must be greater than or equal to the client's portfolio min return value for the timeframe that most closely matches that year.
      • Except when the chosen avg is less than min return, in which case the value is strictly equal to chosen avg.
    • E.g. For a simulation starting in 2022, if the chosen avg for the year 2032 is 5.3% and the 10y min return estimate is 1.5%, that year's min is a random number between 1.5% and 5.3%.

Code​

The source code can be found at src/calc/returns/generateRandomReturns.ts (requires access to the github repository).