1. 8. 2025

5 2

Monte Carlo – MACHR Block Randomization

In the real world of trading, market conditions don’t follow a predictable sequence. Bull markets, bear markets, high-volatility periods, and consolidation phases can occur in vastly different orders across different time periods or instruments. A strategy that performs well during one particular sequence of market regimes might struggle if those same regimes appeared in a different order. This Monte Carlo simulation is specifically designed to test how robust your strategy is to changes in the sequence of market regimes, without destroying the internal characteristics that define each regime period.

The MACHR (Market Condition Historical Randomization) Block Randomization test addresses a fundamental question: “What if the same market conditions occurred, but in a different order?”

When we apply this Monte Carlo test, the simulation introduces a sophisticated form of randomization that operates on blocks of consecutive trades rather than individual trades:

  1. Block Creation: The original trade sequence is divided into blocks of consecutive trades (default 5 trades per block, configurable from 2-50). Each block represents a cohesive period of market behavior, preserving the internal relationships between trades that occurred during similar market conditions.
  2. Bootstrap Block Sampling: Instead of simply shuffling individual trades, the simulation uses bootstrap sampling to randomly select blocks with replacement. This means some market regime periods (blocks) might appear multiple times in a simulation, while others might not appear at all – mimicking how certain market conditions can dominate some periods while being absent in others.
  3. Regime Structure Preservation: Within each selected block, the original trade sequence and timing relationships are maintained. This preserves the authentic market microstructure, entry/exit relationships, and regime-specific behavior patterns that define how your strategy actually performed during those conditions.
  4. Timestamp Reconstruction: After block randomization, the simulation optionally reconstructs chronological timestamps to maintain proper equity curve calculation and performance metrics, ensuring the randomized sequence appears as a plausible alternative market history.

For example, imagine your original backtest contained these trade blocks:

  • Block 1: 5 trades during a trending bull market
  • Block 2: 5 trades during high volatility consolidation
  • Block 3: 5 trades during a bear market decline
  • Block 4: 5 trades during low volatility recovery

One simulation might bootstrap to: Block 2 → Block 1 → Block 2 → Block 4, creating a scenario where volatility periods dominate, trending phases are reduced, and bear markets are completely absent. Another simulation might generate: Block 3 → Block 3 → Block 1 → Block 4, creating a bear-market-heavy scenario followed by recovery.

This test differs fundamentally from individual trade randomization or parameter jitter tests. Rather than testing sensitivity to execution variations or parameter instability, MACHR Block Randomization specifically evaluates regime sequence dependency. It answers whether your strategy’s success was due to a fortunate sequence of market conditions, or whether it would remain robust across different plausible arrangements of the same market regimes.

By running 500+ simulations, you generate a distribution of performance outcomes that reflects how your strategy might perform across different possible “market histories” – each containing the same types of market conditions but in reshuffled sequences. This provides crucial insight into whether your strategy’s edge is truly regime-independent or whether it relies on specific sequences of market conditions that might not repeat in the future.

A strategy that shows consistent performance across all MACHR simulations demonstrates true regime robustness. Conversely, high variance in simulation outcomes suggests the strategy may be overly dependent on the particular historical sequence of market regimes in your backtest data.

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/

Subscribe
Notify of
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Pepe
4. 8. 2025 2:31 pm

Great!!!

Patrick Vale
6. 9. 2025 7:26 pm

I can’t download the file. Only showing text browser Google Chrome.