Markets are not stationary — they cycle between fundamentally different states. A strategy built for a bull market will destroy capital in a bear. Regime awareness is the foundation of adaptive trading.
Three canonical states
Each time you generate a new series, a random price path is created with hidden regime transitions. A model then analyses the series — clustering bars by their rolling return and volatility — and assigns each bar to one of three states. Toggle the overlay to see what it found.
Synthetic price — regimes detected by model
■ Bull Run■ Bear / Crash■ Sideways / Chop
Statistical properties of each regime
Each regime has distinct statistical fingerprints. These differences are exactly what the Gaussian HMM will learn to identify.
Regime
Avg Return / bar
Volatility (σ)
Volume
Autocorrelation
Bull Run
+0.04% to +0.12%
Low–Medium
Rising
Positive (momentum)
Bear / Crash
−0.08% to −0.20%
High
Spike then declining
Negative (reversals)
Sideways / Chop
≈ 0
Medium
Low
Near zero
Bull Run. Consistent positive drift with moderate volatility. Momentum is self-reinforcing — buyers absorb selling pressure. Volume tends to expand as price rises. This is the only regime where our strategy enters long.
Bear / Crash. Negative drift with high volatility and sharp drawdowns. Leverage amplifies losses catastrophically. Our exit rule triggers the moment the HMM assigns this label — no holding through bear markets.
Sideways / Chop. Near-zero mean return with unpredictable direction. Trend-following strategies underperform or lose in this regime. Staying in cash is correct here.
Returns distribution by regime
Each regime's return distribution has a different mean and standard deviation. The curves below are fitted to the bars the model assigned to each regime — in the next lesson we formalise this with probability density functions.
Return distributions — model-detected regimes
Separability is the key. If Bull Run and Bear/Crash returns overlapped completely, no model could tell them apart. The fact that they have different means (positive vs negative drift) gives the model a statistical signal to separate them — even when regime boundaries are gradual and uncertain.