Hidden Markov Model for Market Regime Detection

A Hidden Markov Model (HMM) treats the financial market as being in one of a small number of unobservable “regimes” — most commonly a calm, low-volatility, broadly bullish state and a turbulent, high-volatility, frequently bearish state. The trader never sees the regime directly; they see only observable outputs, usually daily returns or a volatility proxy. The HMM assumes those observations are drawn from a regime-specific distribution (classically Gaussian, x_t ~ N(mu_{s_t}, sigma^2_{s_t})), and that the regime itself follows a first-order Markov chain: the probability of next period’s regime depends only on this period’s regime, encoded in a transition probability matrix with high diagonal values that produce persistent states. This is the same latent-state machinery as the Markov Regime-Switching Model in Hamilton’s econometric tradition; the HMM label is the engineering/signal-processing name for the same object, and in practice the two terms are used interchangeably for Regime Classification.

Hidden Markov Model Regime Detection [part-of] Markov Regime-Switching Model Hidden Markov Model Regime Detection [defines] Regime Classification Hamilton 1989 [defines] Markov Regime-Switching Model Hidden Markov Model Regime Detection [relates] Markov Chain Trading Model

Estimation has two parts. Parameters (the transition matrix and the per-state means and variances) are fit by the Baum-Welch algorithm, an Expectation-Maximisation (EM) procedure that maximises the likelihood of the observed return sequence; because the likelihood is non-convex, practitioners run it from many random or k-means++ starting points and keep the best fit. Once parameters are fixed, the latent regime sequence is recovered either by the Viterbi algorithm — dynamic programming that returns the single most probable global state path — or by local “smoothing” probabilities that give the marginal probability of each state at each date. The distinction matters enormously for trading. Bulla et al. (2011) show the Viterbi path produces far fewer regime switches than smoothing, which directly lowers turnover and Transaction Costs and Slippage; their out-of-sample design therefore decodes with Viterbi and then further suppresses spurious flips with a median filter. Crucially, smoothing in its full-sample form uses future data to label the present, so a backtest that classifies regimes with full-sample smoothed estimates and then “trades” them is contaminated by Lookahead Bias from Smoothed Regime Estimates — the model only looks prescient because it peeked. Honest evaluation requires filtered/online inference, where the regime for day t uses only data up to day t.

Baum-Welch Estimation [defines] Hidden Markov Model Regime Detection Viterbi Decoding [supports] Hidden Markov Model Regime Detection Lookahead Bias from Smoothed Regime Estimates [opposes] Out-of-Sample Backtesting Bulla et al. 2010 [proposes_model] Hidden Markov Model Regime Detection

Regime inference is turned into a decision in one of two ways, and the evidence is sharply different for each. The first is a direct timing rule: the binary “0/1” or “stock-versus-cash” strategy holds 100% equity when the favourable (low-volatility) regime is inferred and 100% risk-free otherwise. Bulla et al. (2011) ran exactly this on daily returns of five indices (DAX, DJIA, NASDAQ 100, Nikkei 225, S&P 500) over roughly 40 years and, after charging 10bp one-way transaction costs in a rolling out-of-sample test, found it profitable: volatility fell on average 41% and annualised excess return ran from a thin 18.5bp (S&P 500) to 201.6bp (Nikkei), lifting Sharpe ratios above the indices’ average of 0.342. But the more recent and more rigorous test by Shu, Yu and Mulvey (2024) — which uses a two-state Gaussian HMM as its explicit benchmark — is far less flattering: over 1990-2023 on the S&P 500, the HMM-guided 0/1 strategy cut max drawdown from -55.2% to -28.9% and volatility from 18.2% to 11.3%, yet its compound annual return of 8.5% FELL BELOW buy-and-hold’s 10.2%. For the DAX the HMM strategy roughly matched the index return, and the authors note HMM-inferred regimes were “numerous short-lived regimes that are unintuitive and difficult to trade,” frequently causing the HMM strategy to UNDERPERFORM buy-and-hold once trading costs and misclassification were counted. This is the central, honestly-graded result: an HMM reliably reduces risk, but standalone return alpha after costs is weak, regime-dependent, and not robust.

Regime-Based Asset Allocation [part-of] Hidden Markov Model Regime Detection Bulla et al. 2010 [reports_profitability] Regime-Based Asset Allocation Shu Yu and Mulvey 2024 [reports_underperformance] Hidden Markov Model Regime Detection Hidden Markov Model Regime Detection [detects_regime] S&P 500 Shu Yu and Mulvey 2024 [includes_costs] Transaction Costs and Slippage

The second use — as a risk filter rather than a signal generator — is where the HMM holds up best. Wang, Lin and Mikhelson (2020) do not trade the regime directly: they use an HMM on the S&P 500 to detect the prevailing regime and then rotate among style-factor models, reporting out-of-sample (Sep 2017-Apr 2020) outperformance versus each individual factor model. Shu et al. (2024) frame the same conclusion negatively: their statistical jump model (Statistical Jump Model), which adds an explicit jump penalty to enforce regime persistence, beat the HMM precisely because the HMM’s regimes flipped too often (around 2 shifts per year even with heavy smoothing, against fewer than one for the jump model), driving HMM turnover of 141-290% versus 44-72% — and that turnover is what destroyed the HMM’s net edge. Baitinger and Hoch (2024) add a complementary warning: the more complex Hidden Semi-Markov Model (Hidden Semi-Markov Model) beats the plain HMM in-sample but that advantage “largely disappears out-of-sample,” and adding more hidden states does not reliably help — a textbook case of Overfitting in Quantitative Trading and a reason to be sceptical of State-Count Selection. Taken together, the literature substantiates the HMM as a useful regime/risk-management filter — it cuts drawdowns and volatility consistently — but does NOT substantiate it as a dependable standalone alpha source after realistic costs, out-of-sample. Failure modes are well documented: Regime Misclassification (especially the ~10% error spike at window edges that Bulla et al. flag, and the ~25-day median latency in detecting turning points), HMM Parameter Instability from noisy estimates on short or bear-starved samples, lookahead bias from smoothed regimes, and the absence of Data-Snooping Bias controls when state counts and smoothing lags are tuned on the same data used to report performance.

Hidden Markov Model Regime Detection [supports] Regime Classification Wang Lin Mikhelson 2020 [tests_strategy] Hidden Markov Model Regime Detection Statistical Jump Model [opposes] Hidden Markov Model Regime Detection Hidden Semi-Markov Model [relates] Hidden Markov Model Regime Detection Regime Misclassification [causes] Hidden Markov Model Regime Detection HMM Parameter Instability [causes] Regime Misclassification State-Count Selection [relates] Overfitting in Quantitative Trading

Connections

Sources