Monte Carlo Simulation

BacktestLM's Monte Carlo engine reshuffles your historical trade sequence 1,000+ times to produce a distribution of possible outcomes — revealing the tail risk your base backtest cannot show.

How the simulation works

After completing a backtest, the engine has a list of individual trade results (each with its P&L, expressed as a percentage return or absolute value). The Monte Carlo simulation:

  1. 1. Takes the complete list of closed trades.
  2. 2. Randomly samples trades with replacement to create a new sequence of the same length.
  3. 3. Computes the equity curve for that sequence.
  4. 4. Records the max drawdown, final return, and losing streak for that simulation.
  5. 5. Repeats 1,000 times (configurable up to 10,000).
  6. 6. Computes the percentile distribution of all recorded metrics.

Output metrics

Max drawdown distribution (5th / 50th / 95th percentile)

The range of maximum drawdowns across all simulations. The 95th percentile is your planning number: in 95% of possible trade sequences, the drawdown was at most this value.

Final return distribution (5th / 50th / 95th percentile)

The range of final account values at the end of the simulation period. The 5th percentile is the bad-luck scenario; the 95th is the lucky scenario.

Worst-case consecutive losing streak

The maximum number of consecutive losing trades across all simulations. Useful for psychological preparation and for ensuring you would not abandon the strategy during a normal losing run.

Probability of ruin

The percentage of simulations where the account fell below a defined threshold (configurable; default 50% loss). A low probability of ruin (< 1%) is important for strategies traded with meaningful position sizes.

Equity curve band

A chart showing the 5th to 95th percentile band of all simulated equity curves, with the median curve highlighted. Provides a visual representation of outcome uncertainty.

Using Monte Carlo for position sizing

The 95th-percentile max drawdown is the key number for position sizing. The process:

  1. 1. Run Monte Carlo at your intended position size.
  2. 2. Compare the 95th-percentile drawdown to your risk tolerance.
  3. 3. If it exceeds your tolerance, scale down position size proportionally (e.g., half position = half drawdown).
  4. 4. Re-run Monte Carlo to confirm the adjusted drawdown is acceptable.

Configuration

Number of simulations

Default: 1,000 (configurable up to 10,000)

More simulations provide smoother distributions but increase BTU cost and computation time.

Ruin threshold

Default: 50% account loss

The level at which an account is considered 'ruined' for probability of ruin calculation. Configurable.

Sampling method

Default: With replacement

Trades are sampled with replacement, meaning the same trade can appear multiple times in a simulation. This is the standard Monte Carlo method for trading.