Backtesting
Monte Carlo Simulation: Stress-Test Your Backtest Before It Goes Live
A single backtest is one path through one period — an anecdote, not proof. Monte Carlo reshuffles your trades into thousands of alternative sequences and shows the distribution: how often the strategy stays profitable, how deep the drawdowns get, and whether the edge beats chance.
Educational content, not investment advice. Trading involves risk of loss.
In brief
- A single backtest is one path through one period — an anecdote. Monte Carlo reshuffles the strategy's own trades into thousands of alternative sequences and reads the distribution of outcomes.
- In a 2,000-path bootstrap of a 60-trade log (+22.75% observed), the strategy stayed profitable in 96.3% of universes — but the 95th-percentile drawdown was 11.21%, nearly double the 6.46% the single backtest showed.
- The permutation test flips each trade's sign at random: only 59 of 2,000 sign-flipped runs matched the observed return (p = 0.03), evidence the edge is real — but Monte Carlo alone cannot prove it; overfitting survives every resample.
- Size on the 95th-percentile drawdown, not the headline return. Below ~80% probability of profit, a 95th-percentile drawdown past your limit, or a p-value above 0.05, the strategy is not deployable yet.
On this page
The short answer
A single backtest is one path through one historical period — an anecdote, not proof. Monte Carlo simulation takes the trades your backtest actually produced, reshuffles them into thousands of alternative sequences, and shows the distribution of outcomes: how often the strategy stays profitable, how deep the drawdowns get, and whether the edge is distinguishable from luck. Run it before you put real capital behind any strategy. If the strategy is only profitable in the one order history happened to deliver, you do not have an edge — you have a story.
Why one backtest is an anecdote
A backtest produces exactly one equity curve. That curve is the product of a specific sequence of wins and losses, in a specific order, over a specific period. Change the order and the curve changes — sometimes dramatically — even though the trades themselves are identical. A losing streak that lands early, before the account has built a cushion, produces a far deeper drawdown than the same losing streak landing late.
This is the problem Monte Carlo exists to solve. Instead of asking "did this strategy make money on this history?", it asks "given the trades this strategy produces, in how many plausible orders does it stay profitable, and how bad does it get?" The answer is a distribution, not a single number — and a distribution is what you need before risking money.
Two tests do most of the work: bootstrap resampling measures the range of outcomes, and the permutation test measures whether the result is distinguishable from chance at all.
Bootstrap resampling: a thousand parallel universes
The method is simple. Take the complete list of trade returns from your backtest. For each simulation, draw the same number of trades from that list at random, with replacement — the same trade can appear twice, another may never appear — and rebuild the equity curve. Repeat a thousand times or more. Each simulation is a parallel universe in which the same edge expressed itself in a different order.
Stack the results and read the distribution: the probability of ending in profit, the 5th and 95th percentile outcomes, the median and 95th percentile maximum drawdown, and the chance of a drawdown past your pain threshold. Use the actual trade returns, not an assumed distribution, and compound them — rebuild the equity curve trade by trade — because drawdown depends on the path, and the path is exactly what you are testing.
What the numbers actually look like
Here is a concrete run. The trade log is synthetic but the model is stated: 60 trades from a simple crossover strategy, 29 wins (48.3%), average win +1.79%, average loss −0.99%. The single backtest shows +22.75% total return with a 6.46% maximum drawdown. Respectable. Now reshuffle it 2,000 times:
import random
rng = random.Random(7)
trades = [] # 60 trades: 29 wins (+0.8% to +2.8%), 31 losses (-0.5% to -1.5%)
for _ in range(60):
if rng.random() < 0.45:
trades.append(round(rng.uniform(0.008, 0.028), 4))
else:
trades.append(round(-rng.uniform(0.005, 0.015), 4))
finals, dds = [], []
for _ in range(2000):
eq, peak, dd = 1.0, 1.0, 0.0
for _ in range(60):
eq *= (1 + rng.choice(trades)) # draw with replacement
peak = max(peak, eq)
dd = max(dd, (peak - eq) / peak)
finals.append(eq); dds.append(dd)
finals.sort(); dds.sort()
The distribution, on $10,000 of starting equity:
| Metric | Result |
|---|---|
| Probability of profit | 96.3% |
| Final equity, 5th percentile | $10,198.89 |
| Final equity, median | $12,241.03 |
| Final equity, 95th percentile | $14,796.16 |
| Max drawdown, median | 6.03% |
| Max drawdown, 95th percentile | 11.21% |
| Chance of a 10%+ drawdown | 9.2% |
Read it plainly. The strategy stays profitable in 96 out of 100 universes, and even the bad 5% still ends above water at $10,198.89. But the drawdown tail is real: one path in eleven breaches 10%, and the 95th-percentile drawdown is 11.21% — nearly double the 6.46% the single backtest showed. If your account cannot absorb an 11% drawdown without you changing how you trade, the headline return is not the number to size on. The 95th percentile is.
The permutation test: is the edge real?
Bootstrap tells you the range of outcomes assuming the trades are real. The permutation test asks a harder question: is there an edge at all? Take the same 60 trade returns and randomly flip each one's sign — a win becomes a loss of the same size, a loss becomes a win. That simulates a strategy that enters in a random direction while keeping the exact distribution of return magnitudes. Repeat 2,000 times and count how often the sign-flipped version matches or beats your observed return.
On this trade log, 59 of 2,000 sign-flipped runs matched or beat the observed +22.75% — a p-value of 0.03. If the strategy had no directional skill, you would see a result this good about 3% of the time by chance alone. That is evidence of an edge, not proof of one — and far stronger evidence than the single equity curve alone. The permutation approach is described in the TradingView guide cited below, which traces it to Aronson (2006).
Run both tests together. A strategy can pass the permutation test and still fail Monte Carlo — a real edge with a ruinous drawdown tail — or pass Monte Carlo and fail the permutation test, which means the pretty distribution is built on luck.
What Monte Carlo cannot tell you
Three limits, stated plainly, because they are where people get hurt.
First, every resample draws from the same trades. A strategy overfitted to its sample is overfitted in every resample of that sample. Monte Carlo tests path risk, not whether the edge is real — that is what walk-forward validation and out-of-sample testing are for. Run Monte Carlo after the out-of-sample test, never instead of it.
Second, shuffling assumes trades are interchangeable. Trend-following strategies and anything sized off recent performance produce clustered wins and losses; reshuffling destroys that clustering and reports a drawdown that is optimistically biased. If your trades cluster, use a block bootstrap that preserves runs of consecutive trades, and treat the plain-shuffle numbers as a floor, not an estimate.
Third, Monte Carlo says nothing about the future regime. It replays your trades; it cannot invent a market your strategy has never seen. A strategy that has only traded a bull market will Monte-Carlo beautifully right up until the market changes. That is why the out-of-sample period should include a different regime, and why overfitting is the first failure mode to rule out.
How to read the results
Three numbers decide whether a strategy is deployable. Probability of profit below about 80% means the edge is too thin to trust — one bad ordering and you are underwater. A 95th-percentile drawdown above your stated maximum means the strategy will, sooner or later, put you in a hole you have already decided you cannot trade through. And a permutation p-value above 0.05 means you cannot distinguish the result from luck, whatever the equity curve says.
If a strategy fails any of the three, the fix is not more Monte Carlo runs. It is a better strategy, a smaller size, or a longer out-of-sample period. Position sizing is where the drawdown numbers turn into a size decision, and drawdowns and volatility targeting show what the backtest hides about the downside.
What to do next
Take your best backtest's trade log and run both tests tonight — the code above is the whole engine, and it runs in seconds. If the strategy passes all three numbers, size it on the 95th-percentile drawdown, not the headline return. If it fails, you have learned something cheap: the backtest was a story, and the story cost you an evening instead of an account.
If the testing itself is the bottleneck — the harness, the resampling, the broker connection to run it live — that is the kind of build the engineering desk does. BlackShore Agency is the engineering firm inside Blackshore Technologies, the same parent company as Quantide, and a desk engineer can wire Monte Carlo, walk-forward, and live execution into one pipeline so every strategy is stress-tested before it trades a dollar.
Frequently asked questions
Does passing a Monte Carlo test prove a strategy works?
No. Every resample draws from the same trades, so a strategy overfitted to its sample is overfitted in every resample. Monte Carlo tests path risk; walk-forward and out-of-sample testing test whether the edge is real. Run Monte Carlo after the out-of-sample test, never instead of it.
What numbers should I read off a Monte Carlo run?
Probability of profit, the 5th/95th percentile final equity, and the median and 95th percentile maximum drawdown — plus the chance of a drawdown past your pain threshold. Size on the 95th-percentile drawdown, not the headline return.
How many Monte Carlo simulations should I run?
At least 1,000 simulations, and 2,000 is a comfortable standard. Below a few hundred, the tail percentiles — the numbers you actually size on — are too noisy to trust.
What if my trades cluster — winning and losing streaks?
Use a block bootstrap that preserves runs of consecutive trades, and treat plain-shuffle drawdown numbers as a floor, not an estimate. Shuffling destroys the clustering and reports an optimistically shallow drawdown.
Sources
Related reading
- GuideHow to Backtest a Trading Strategy in Python, End to EndA backtest you can trust is a process, not a number: fixed data, one rule stated in advance, fees and slippage from the first run, and a judgement made only on data the strategy has never seen. This guide runs the whole process in Python, with the complete script.6 min read
- GuideSurvivorship Bias: The Backtest Data That Only Shows the WinnersA third of the S&P 500 from 2016 is gone. If your backtest runs on today's members, it never met the losers — and its returns are flattered by roughly 1–2 percentage points a year. Here is the mechanism, the measured size of the bias, and a simulation that shows it.6 min read
- GuideOverfitting in Backtesting: Why Your Best Parameters Won't Survive Live TradingYour best backtest is usually your luckiest one. Run 200 rules on data with no edge at all and the winner posts a 1.68 Sharpe, then scores 0.01 out of sample. Here is the math behind the winner's curse, and the four checks that stop it.5 min read
- GuideHow to Build Your First TradingView Strategy in Pine Script v6Pine Script v6 is TradingView's current language for systematic strategies. Build a complete moving-average crossover strategy in about 30 lines, run it in the Strategy Tester, and read the result without fooling yourself — including what TradingView's November 2026 rule reversal means for script authors.7 min read