Several articles on this site use interactive simulation components that let you experiment with parameters and see results in real time.

This article is a comprehensive walkthrough of the five components:

  1. Compound interest — deterministic growth model
  2. Rebalancing visualiser — a single stochastic simulation with four strategies
  3. Monte Carlo simulator — hundreds of parallel simulations with statistics
  4. Optimal rebalance frequency — comparison of six frequencies under taxation
  5. Volatility harvesting simulator — isolates the pure rebalancing bonus with two identical assets

For each component this article covers: what it shows, what settings it has, the maths behind it, and what it cannot tell you.


1. Compound Interest

What it shows

This is the simplest of the three components. It shows a deterministic (non-random) growth path for an investment over time.

There are two curves:

  • Portfolio value — what you have, year by year
  • Invested capital — the flat line showing your starting amount

The difference between them is the accumulated return — the classic illustration of the compound interest effect.

Settings

SettingDefaultRange
Initial capital100,00010,000 – 1,000,000
Annual return7 %1 – 20 %
Years305 – 50

The maths

The calculation is simple exponential growth:

V(t)=K(1+r)tV(t) = K \cdot (1 + r)^t

Where KK is the starting capital, rr is the annual return, and tt is the number of years.

The code applies it recursively year by year, but the result is identical:

V(0) = K
V(t) = V(t−1) · (1 + r)

Limitations

  • No volatility. The return is constant every year. In reality returns fluctuate — up and down.
  • No inflation. All amounts are in nominal currency, not real.
  • No tax. The compound effect looks more impressive than it does in practice, because tax is not deducted along the way.
  • No contributions or withdrawals. Only one starting deposit; no ongoing cash flows.

The component is useful for illustrating the principle of exponential growth — but not for predicting what your portfolio will actually be worth.


2. Rebalancing Visualiser

What it shows

This component runs a single stochastic simulation and displays four curves on the same chart:

  • Stocks (100%) — a pure equity portfolio
  • Bonds (100%) — a pure bond portfolio
  • Rebalanced — before tax — a mixed portfolio continuously brought back to the target allocation, without any tax deduction
  • Rebalanced — after tax — the same strategy, but with a tax charge on realised gains at each rebalance

The key point is that all four curves use identical random market movements. The difference is due solely to the portfolio strategy — not to the random draws.

The “New simulation ↻” button generates a fresh set of random market movements.

Settings

Settings are grouped into three sections:

Market scenario

SettingDefaultWhat it is
Stock return7 %Expected average annual return for equities
Stock volatility18 %Standard deviation of annual equity returns
Bond return3 %Expected average annual return for bonds
Bond volatility6 %Standard deviation of annual bond returns
Correlation0Pearson correlation between stock and bond shocks
Years20Simulation horizon in years

Portfolio setup

SettingDefaultWhat it is
Stock allocation60/40Target weight for equities (bonds fill the rest)
Tax rate27 %Tax rate on realised gains at rebalancing

Rebalancing settings

SettingDefaultWhat it is
FrequencyEvery yearCalendar-based trigger: every 1–10 years, or never
Drift thresholdNoneOnly rebalance if the stock weight has drifted more than X pp from the target

When frequency is set to Never, the after-tax rebalancing curve is hidden (since no rebalancing takes place).

When the drift threshold is set to e.g. ±5 pp, rebalancing only occurs when the calendar trigger fires and the drift exceeds 5 percentage points.

The maths

Geometric Brownian Motion (GBM)

Returns for each year are drawn as log-normal factors based on geometric Brownian motion:

S(t+1)=S(t)exp ⁣((μ12σ2)+σZ),ZN(0,1)S(t+1) = S(t) \cdot \exp\!\bigl((\mu - \tfrac{1}{2}\sigma^2) + \sigma Z\bigr), \quad Z \sim \mathcal{N}(0,1)

This model is standard in financial theory (Black-Scholes) and has two important properties:

  • Prices can never go negative
  • The geometric mean return is correct even though each year’s return varies

The term μ12σ2\mu - \tfrac{1}{2}\sigma^2 is an Itô correction: it ensures that the geometric mean return matches the desired parameter μ\mu, rather than the arithmetic mean.

Box-Muller transform

The standard-normal values ZZ are generated using the Box-Muller transform from two uniformly distributed values u1u_1 and u2u_2:

Z=2lnu1cos(2πu2)Z = \sqrt{-2\ln u_1} \cdot \cos(2\pi u_2)

Correlation via Cholesky decomposition

When the correlation parameter ρ\rho is non-zero, correlated shocks are produced via Cholesky decomposition of the 2×22\times2 correlation matrix:

zstocks=z1,zbonds=ρz1+1ρ2z2z_\text{stocks} = z_1, \qquad z_\text{bonds} = \rho \cdot z_1 + \sqrt{1-\rho^2} \cdot z_2

This gives exactly Corr(zstocks,zbonds)=ρ\operatorname{Corr}(z_\text{stocks},\, z_\text{bonds}) = \rho.

A negative correlation (e.g. −0.3) models the classic flight-to-safety effect, where bonds rise when equities fall.

Tax calculation at rebalancing

When an asset class is sold to bring the portfolio back to its target allocation, tax is calculated on the realised gain:

Sold fraction  = sale amount ÷ current market value
Taxable gain   = (market value − cost basis) × sold fraction
Tax paid       = taxable gain × tax rate  (only if positive)

The cost basis is updated proportionally for the sold fraction.

Limitations

  • One simulation at a time. A single path can look very different from another — click “New simulation” to see the spread.
  • Two asset classes only. The model supports only equities and bonds. Real estate, commodities, currencies, etc. are not included.
  • Constant parameters. Returns and volatility are assumed constant throughout the period. In reality, market regimes shift.
  • Full rebalance to target. Transaction costs (brokerage fees) are not accounted for.
  • Simplified tax model. The model assumes realisation-based taxation. ETFs and pension accounts subject to mark-to-market taxation behave differently.
  • No new contributions. Only one starting deposit.

3. Monte Carlo Simulator

What it shows

The Monte Carlo simulator runs hundreds of independent simulations in parallel and displays the statistical distribution of possible outcomes.

Unlike the rebalancing visualiser, this component compares two strategies:

  • Buy & hold — no rebalancing (deferred tax)
  • Rebalanced — ongoing rebalancing with tax on realised gains

For each strategy the result is displayed either as:

  • Spaghetti chart — all individual simulation paths
  • Fan chart — the median plus the 10th, 25th, 75th and 90th percentiles as shaded bands

Below the charts, histograms show the distribution of final values, along with statistical key figures (10th percentile, median, 90th percentile).

Settings

The settings are the same as in the rebalancing visualiser, with a couple of additions:

SettingDefaultWhat it is
Initial capital100,000Starting amount for all simulations
Stock return7 %Expected average annual return for equities
Stock volatility18 %Standard deviation of annual equity returns
Bond return3 %Expected average annual return for bonds
Bond volatility6 %Standard deviation of annual bond returns
Correlation0Pearson correlation between stock and bond shocks
Stock allocation60/40Target weight for equities
Tax rate27 %Tax rate on realised gains
Years20Simulation horizon
Simulations500Number of independent simulation paths
FrequencyEvery yearRebalancing frequency
Drift thresholdNoneDrift band before rebalancing is triggered

The buy & hold histograms show two series:

  • Deferred tax — portfolio value without deducting tax on accumulated gains (you still own them)
  • After exit tax — as if you sell everything and pay tax on all gains at the end

The maths

The simulations use the same GBM model with Cholesky correlation as the rebalancing visualiser. The difference is that N independent simulations are run instead of one.

Percentile calculation

For each year tt, all NN simulation values are sorted and percentiles are computed via linear interpolation (the same method as NumPy’s default):

i=p100(N1),v^p=vi(1w)+viw,w=iii = \frac{p}{100} \cdot (N-1), \qquad \hat{v}_p = v_{\lfloor i \rfloor}(1-w) + v_{\lceil i \rceil}\,w, \quad w = i - \lfloor i \rfloor

The histogram

The final values from all N simulations are divided into 20 equal-width bins from minimum to maximum. To make the two strategies’ histograms directly comparable, both use the same bin boundaries — otherwise the bar widths would differ and the comparison would be misleading.

Buy & hold with exit taxation

For buy & hold there are no tax payments along the way. But two versions are shown:

  • Deferred tax: the portfolio value is the raw market value
  • Exit taxation: tax is deducted from the final value as if everything is sold: final value − (final value − starting capital) × tax rate (only if a gain)

Limitations

  • Stochastic, not predictive. The Monte Carlo simulation shows a probability distribution of possible outcomes — not a forecast of the future.
  • Independent years. The model assumes each year’s return is independent of previous years. Autocorrelation and mean reversion (which some empirical studies suggest) are not modelled.
  • Log-normal distribution. Returns are assumed log-normal (thinner tails than reality). Extreme events such as financial crises are under-represented.
  • Constant parameters. Volatility is constant — there is no volatility clustering (where periods of high turbulence tend to be followed by more high turbulence).
  • Two asset classes. The same limitation as the rebalancing visualiser.
  • No transaction costs.
  • Number of simulations vs. precision. 500 simulations gives reasonable statistical stability for illustrative purposes, but extreme percentiles (e.g. 5th and 95th) are less reliable than the median and 10th/90th percentiles.

4. Optimal Rebalance Frequency

What it shows

This component asks the question: which rebalancing frequency produces the best outcome under taxation?

It runs Monte Carlo simulations for six fixed rebalancing frequencies and plots the median final portfolio value for each as a line:

X-axis labelFrequency
NeverNo rebalancing (buy & hold)
10yRebalance every 10 years
5yRebalance every 5 years
3yRebalance every 3 years
2yRebalance every 2 years
1yRebalance every year

The point on the line with the highest median final value is highlighted with a marker and the text “Optimal” above it. A caption below the chart names the optimal frequency in plain text.

The purpose is not to give a definitive answer, but to illustrate how taxation shifts the optimal frequency: because rebalancing triggers tax on realised gains, there is a trade-off — rebalancing too often costs too much in tax, while rebalancing too rarely lets the portfolio drift far from its target allocation.

Settings

The component has no sliders for rebalance frequency or drift threshold — those are the x-axis of the chart. Instead, you can adjust all the parameters that determine what the optimal frequency is:

SettingDefaultWhat it is
Stock return7 %Expected average annual return for equities
Stock volatility18 %Standard deviation of annual equity returns
Bond return3 %Expected average annual return for bonds
Bond volatility6 %Standard deviation of annual bond returns
Correlation0Pearson correlation between stock and bond shocks
Years20Simulation horizon
Simulations300Number of independent simulation paths per frequency
Tax rate27 %Tax rate on realised gains at rebalancing
Drift thresholdNoneOnly rebalance if the stock weight has drifted more than X pp from the target

The maths

The component uses exactly the same GBM simulation engine as the Monte Carlo simulator. For each of the six frequencies:

  1. N sets of random market movements are generated (one set per simulation)
  2. All six frequencies are simulated using the same random draws
  3. The median final value is computed across the N simulations

Sharing identical random draws across all six frequencies is essential: it ensures that differences in median final value are due solely to the rebalancing strategy — not to the composition of the random numbers in a given run.

Tax as a brake on frequent rebalancing

The effect is intuitively understandable: rebalancing is a form of volatility harvesting — selling what has risen and buying what has fallen, capturing the benefit of ongoing price fluctuations. But under a realisation-based tax regime, every sale costs tax on the gain. This reduces the capital base that subsequently grows exponentially. The more frequently you rebalance, the more tax you pay, and the less capital remains to compound.

The optimal point is where the marginal benefit from additional rebalancing is exactly offset by the marginal tax cost.

Limitations

  • Median is not the only criterion. The component uses median final value. A risk-averse criterion (e.g. the 10th percentile) may give a different optimum.
  • Stochastic variation. With 300 simulations per frequency, the median is reasonably stable, but click “New simulation” to see how much the optimum can vary between runs.
  • Same limitations as the Monte Carlo simulator otherwise: no new contributions, constant parameters, log-normal distribution, two asset classes only.

5. Volatility Harvesting Simulator

What it shows

This component isolates the pure rebalancing bonus by removing any return difference between the two assets. Both assets have identical expected return and identical volatility — the only thing that varies is the correlation between them.

Two strategies are compared:

  • Single asset (buy & hold) — 100 % invested in one asset, never rebalanced
  • Rebalanced 50/50 (no tax) — both assets held in equal weight, rebalanced annually, no tax

Because the assets are identical, any difference in outcome is entirely due to the rebalancing mechanism itself — not to any expected-return premium from holding one asset over another.

The chart shows fan bands (10th–90th percentile range) and median lines for both strategies. Below the chart, two statistics are displayed:

  • Theoretical premium (p.a.) — calculated directly from the formula σ24(1ρ)\frac{\sigma^2}{4}(1-\rho)
  • Simulated premium (p.a.) — the annualised ratio of the two median final values

Settings

SettingDefaultRange
Asset return7 %−5 % to 20 %
Asset volatility20 %5 % to 50 %
Correlation0−0.9 to +0.9
Years205–40
Simulations300100–1000

Note: “Asset return” and “Asset volatility” apply to both assets identically. There is no separate stock/bond distinction in this component.

The maths

The simulation uses the same GBM engine with Cholesky correlation as the other components. Both assets are generated with the same parameters; their shocks are coupled at the specified correlation.

For the single-asset strategy, the portfolio simply tracks one asset’s cumulative return factor. For the rebalanced strategy, simulatePortfolio is called with stockAllocation = 0.5, rebalanceFrequency = 1, and taxRate = 0.

The theoretical premium

For two equal-weight assets with identical volatility σ\sigma and correlation ρ\rho:

  • Portfolio variance: σp2=σ22(1+ρ)\sigma_p^2 = \frac{\sigma^2}{2}(1+\rho)
  • Single-asset variance: σ2\sigma^2
  • Arithmetic–geometric gap saved by rebalancing: σ22σ24(1+ρ)=σ24(1ρ)\frac{\sigma^2}{2} - \frac{\sigma^2}{4}(1+\rho) = \frac{\sigma^2}{4}(1-\rho)

The annual rebalancing premium is therefore:

premiumσ24(1ρ)\text{premium} \approx \frac{\sigma^2}{4}(1-\rho)

This premium exists because the rebalanced portfolio has lower variance than either single asset, and lower variance means a smaller drag on compounded returns.

The simulated premium

The simulated premium is computed from the median paths:

simulated premium=(median final value (rebalanced)median final value (single asset))1/T1\text{simulated premium} = \left(\frac{\text{median final value (rebalanced)}}{\text{median final value (single asset)}}\right)^{1/T} - 1

This should converge to the theoretical value as the number of simulations increases.

Limitations

  • Tax-free only. The rebalanced strategy assumes no tax on realised gains. In taxable accounts the rebalancing premium must be weighed against the tax cost — see Rebalancing vs. Danish Taxation.
  • Identical assets. The component deliberately uses two identical assets to isolate the rebalancing effect. A real portfolio has assets with different expected returns, which introduces additional dynamics not shown here.
  • Annual rebalancing only. The rebalancing frequency is fixed at once per year. More or less frequent rebalancing would give different results.
  • All the standard Monte Carlo limitations apply: no new contributions, constant parameters, log-normal distribution, independent years.

Common to all five components

What they can do

  • Illustrate mathematical principles — compound interest, volatility harvesting, tax effects
  • Build intuition for magnitudes and relative differences
  • Let you experiment with parameters and see the immediate effect

What they cannot do

  • Predict the future. No financial model can.
  • Account for your specific situation — account type, tax circumstances, investment horizon, risk tolerance.
  • Model all asset classes. Real estate, gold, private equity, currencies etc. are not included.
  • Include behavioural risk — the risk that you sell in panic during a market downturn.
  • Replace personal advice from a financial adviser or tax specialist.

Technical details

Random number generator

JavaScript’s Math.random() is a pseudo-random number generator — not cryptographically secure, but sufficient for financial simulations for illustrative purposes.

Debouncing

To avoid running hundreds of simulations for every single slider movement, debouncing is used: the calculation is only triggered 300 ms after you stop adjusting. This gives a responsive interface without overloading the browser.

Freezing random draws

In the rebalancing visualiser, the random market movements are generated once, and all four strategies are then simulated using the same draws. This ensures that differences between the curves are due solely to the strategy — not to the random numbers.

In the Monte Carlo simulator, the same principle is applied to the buy & hold vs. rebalancing comparison: each pair of simulations (BH and RB) uses identical market movements.

In the optimal rebalance frequency component, the principle is extended further: all six frequencies share the same set of random draws. This means the line in the chart is a pure function of the rebalancing strategy — not of the particular random numbers drawn in that run.

In the volatility harvesting simulator, the same freeze is applied: both the single-asset strategy and the rebalanced strategy use identical draws for each simulation path. This means the gap between the two median lines is attributable purely to the rebalancing mechanism.