Monte Carlo – Simulate Parameter Jitter
In the real world of trading, market conditions are constantly evolving. Volatility shifts, liquidity fluctuates, and the data feed itself might have minute variations from tick to tick. Consequently, even a well-optimized strategy might not perform exactly as predicted by a backtest, as its core parameters or indicator calculations could experience slight “jitter” or instability when faced with live conditions. This Monte Carlo simulation is designed to test how resilient your strategy is to such minor, unpredictable deviations from its perfect backtest behavior.
If we apply this Monte Carlo test, the simulation introduces two potential effects on the trades within each generated backtest run:
-
Condition Flicker (Missed Entries): Based on the Skip Probability, a random percentage of trades are simply removed from the backtest. This simulates instances where slight parameter jitter might cause an entry condition, which was met in the historical backtest, to be narrowly missed in a slightly different live scenario.
-
Exit Level Variation (P/L Fluctuation): For the trades not skipped, a further random percentage (defined by Adjust Probability) will have their final outcome slightly altered. This is done by modifying the Close Price of the trade. The modification amount is calculated as a random percentage (up to the Max Price Adjust Percent) of that specific trade’s original price range (Open to Close). Crucially, this adjustment can be positive or negative, meaning the jitter effect might randomly result in a slightly better or slightly worse closing price, simulating minor variations in Stop Loss, Profit Target, or trailing stop execution points.
Simply put, by running 500 (or a different number) simulation backtests, each applying different random skips and random bi-directional price adjustments to the trade list, you gain a Monte Carlo perspective on how sensitive your strategy’s performance is to small, random instabilities in its own execution logic or its reaction to market data.
For instance, running 100 simulations using this test will generate 100 different equity curves, each representing a plausible outcome path considering these minor random variations.
This test differs significantly from applying fixed slippage or simulating random downtime. It doesn’t just degrade results consistently; it introduces a probabilistic disturbance directly related to the strategy’s potential internal parameter sensitivity. One simulation might skip trades #3 and #25, slightly worsen trade #10, and slightly improve trade #42. Another simulation might skip only trade #15 but apply larger price adjustments (both positive and negative) to trades #8, #33, and #50. By assessing the distribution of outcomes across many simulations, you can evaluate the true robustness of the strategy against the kind of subtle operational variations often encountered live.
How to import custom snippets (like this Monte Carlo test) to SQX:
https://strategyquant.com/doc/programming-for-sq/import-export-custom-indicators-and-other-snippets/