Regime SwitchingRisk: Medium

Markov Switching

Each market regime has its own α and σ — trade accordingly, automatically

Risk

Medium

Holding Period

Varies — monthly rebalance with state transitions

Best For

Assets with identifiable bull/bear regimes (equities, commodities)

How it works

HMM_regime tells you 'we're in a crisis now' but stops there. Markov Switching Regression (Hamilton 1989) goes further: it fits a DIFFERENT regression per regime, so you get interpretable per-regime parameters — e.g. regime 0 has α = +8bps/day, regime 1 has α = −5bps/day. The signal is then mechanical: read the filtered probability of the current regime, look up that regime's α, long if positive and large enough, short if negative and large enough. Filtered probabilities (not smoothed) are used so the signal has no look-ahead.

Mathematical Foundation

y_t = α_{s_t} + ε_t, ε_t ~ N(0, σ²_{s_t}) s_t ∈ {0, 1} with transition matrix P

Signal Generation Logic

  1. 1For each asset, fit a 2-regime Markov Switching Regression to its daily returns using statsmodels
  2. 2Extract per-regime constants α_k (daily expected return) and variances σ²_k
  3. 3At each rebalance date, read the FILTERED (not smoothed) probability P(s_t = k | observations ≤ t) — no look-ahead
  4. 4Current regime = argmax of filtered probabilities
  5. 5If regime probability < min_regime_prob (default 0.70), stay flat — we're not confident enough
  6. 6Otherwise: look up current regime's α_daily; annualize × 252. Long if > min_annual_alpha_pct, short if < −min_annual_alpha_pct, else flat
  7. 7Confidence = min(|α_annual| / 10%, 1) × regime_prob. State-transitions only (no repeated identical signals)

Parameters Explained

k_regimes

Number of hidden regimes. 2 is the sweet spot — 3+ often overfits on finite data. Must be ≥ 2.

Default

2
min_annual_alpha_pct

Trade only when the current regime's expected annual return exceeds this magnitude. Filters out 'weak edge' regimes that would lose to transaction costs.

Default

2%
min_regime_prob

Minimum filtered probability for the top regime. Lower values = more trading but noisier calls. 0.70 is reasonable for 2-regime FX/equity.

Default

0.70
rebalance_freq

How often to re-read the filtered probability. Monthly matches the pace of regime shifts; weekly catches transitions faster but increases turnover.

Default

monthly

When It Works

Equity indices and commodities that alternate between well-defined bull/bear regimes (SPX, gold in 2000-2011 vs 2012-2019). MSR excels at the 'we know things are different now but can't articulate why' situation — the model captures the shift without needing a narrative.

When It Fails

Assets with gradual parameter drift rather than discrete regime jumps. The filter expects observations to cluster around K different means; a smooth continuum (steadily trending asset) gives degenerate regime fits. Also: when regime transitions happen intra-bar (flash events), the filter only picks up the shift after several observations.

Risks & Limitations

  • Regime labels are statistical, not economic. The model may identify a 'low vol regime' that cuts across what humans would call 'bull' and 'bear'
  • The fit is done once over the full history — filtered probabilities respect causality but the PARAMETERS were fit with data we didn't have at time t. Full walk-forward would be more honest but 100× more expensive
  • EM convergence is not guaranteed; statsmodels sometimes returns flat regimes on pathological data. The strategy logs and skips these cases
  • 2 regimes vs 3+: we chose 2 for interpretability, but regime transitions can be more granular than that in reality

Implementation

Uses statsmodels.tsa.regime_switching.MarkovRegression with trend='c', switching_variance=True. We parse param_names (['p[0->0]', 'p[1->0]', 'const[0]', 'const[1]', 'sigma2[0]', 'sigma2[1]']) to extract regime means and variances. filtered_marginal_probabilities drives the trading signal — purely causal. Signals emit only on state transitions.

Model parameters

k_regimes

Number of hidden regimes fitted per asset

2

Min Annual α

Expected-return threshold to trade

2%

Min Regime Prob

Minimum filtered probability to call a regime

0.70

Rebalance

Re-read the filtered probability at month start

Monthly

Academic background

Academic Basis

Based on Hamilton (1989), 'A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle', Econometrica — extended with per-regime regression coefficients

Backtest this strategy

Run the exact model on your selected assets and date range. See trade-by-trade performance.

Backtest This