A backtest gives you a number: total PnL, Sharpe, max drawdown. The first two are (roughly) order-independent if you're just summing returns. Max drawdown is not. Neither is the probability that your equity curve touches a ruin threshold before the backtest window ends.
According to recent reports, consider two strategies with identical trade lists: same 300 trades, same total PnL, same win rate. One sequence happens to cluster its losses early and its wins late. The other does the reverse. Same totals, radically different drawdowns, radically different risk of blowing up mid-stream. Your backtest only sampled one of the possible orderings — the one that actually happened, or worse, the one your optimization pipeline selected for. (Related: Steam is pitting 10 years of Game of the Year winners a...)
A Monte Carlo permutation test fixes this cheaply. Shuffle the realized trade PnL sequence thousands of times, recompute max drawdown and ruin indicators on every shuffle, then look at the resulting distribution. If your backtest's drawdown sits at the 5th percentile of the shuffled distribution, your headline number is flattering you. If it sits near the median, the strategy's risk is roughly order-neutral and you can trust the backtest more.
It has been revealed that the key assumption: the multiset of trade PnLs is fixed, only the order is random. This tests sensitivity to sequencing, not to whether the trades themselves were lucky. It's a stress audit of path risk, not a validation of edge.
Assume you have a vector of per-trade PnL in account currency (or in R-multiples — the math is identical, only the ruin thresholds change units). (Related: Man calls police on his ex for taking back her Xbox acc...)
The permutation test only cares about the values, not their original order. If you want to audit the actual backtest drawdown, keep the original array around — you'll compare it against the shuffled distribution.
Sources indicate that the naive approach loops over 5000 shuffles in Python and calls np.cumsum each time. That's fine for 300 trades but painful at 5000 trades × 5000 shuffles. Vectorize it: build a matrix of shape (n_sims, n_trades), cumsum along axis 1, then compute running max and drawdown per row.
It has been revealed that for 5000 trades and 5000 simulations, that's a 25M-element float64 array — about 200 MB. If memory is tight, chunk the simulations:.
It has been revealed that max drawdown is one number per shuffle. Ruin probability is the fraction of shuffles where the equity curve drops below a threshold at any point. Compute it directly from the drawdown matrix — no extra pass needed.
In a recent development, pass thresholds in the same units as your PnL. If you're sizing in R-multiples and risking 1% of equity per trade, a 20R drawdown is roughly a 20% equity hit (ignoring compounding). Pick thresholds that map to real operational limits: margin call levels, a hard stop-loss on the strategy, a psychological "I'd shut this down" number.
In a recent development, sometimes you want this in a script with no numpy dependency — a research notebook on a locked-down box, a quick check in a CI step, or a port to another language. The pure-Python version is 20 lines and fast enough for a few hundred trades.
random.Random.shuffle mutates the list in place, so you don't rebuild it every iteration — that's the main cost saver. If you need ruin probabilities too, track the minimum equity inside the loop and collect it. For 1000 trades × 5000 sims this takes a few seconds; the numpy version is roughly 50–100× faster.
It has been revealed that now the part that actually matters. You have a distribution of 5000 max drawdowns. What do you do with it?
The percentile of your backtest DD tells you how flattering the realized order was. A backtest DD at the 10th percentile means 90% of orderings produce a worse drawdown — the strategy's risk is understated. At the 50th, you're unbiased. At the 90th, your backtest was unusually unlucky and the strategy is probably better than it looks (rare, but it happens with short samples).
A concrete rule that works in practice:.
Sources indicate that one caveat worth stating plainly: this test assumes trade PnLs are exchangeable. Real strategies have autocorrelation — volatility clustering, regime shifts, correlated losses during stress. Permutation tests ignore that, so they can understate tail drawdowns when losses cluster. If you suspect serial dependence, the permutation test is a lower bound on path risk, not an upper one. Combine it with a block bootstrap or a regime-conditional analysis if the strategy is sensitive to volatility regimes.
It tells you whether your backtest drawdown is representative of the drawdown distribution over all orderings of the same trades. It does not tell you whether the trades themselves are predictive, whether the sample is large enough, or whether the strategy will work out of sample. Those are separate questions with separate tests.
In a recent development, what it does well: it catches the specific failure mode where a strategy looks safe because the backtest got a lucky ordering. That failure mode is common, cheap to test for, and expensive to discover live. Five thousand shuffles and a percentile lookup is a small price.
More notes like this ship every week on this site.
The following pairs are selected from the multi-timeframe trend scanner (Gate.io futures) and are for technical-analysis study only — not investment advice. Data updated: 2026-11-09 08:46:35.
Sources indicate that 2 picks selected. Scanner runs every 15 minutes.
