Portfolio LabKnowledgeSign inCreate account

Regime models: hidden Markov, Markov switching and more

Advanced13 min read · 19 sources

Regime models assume that markets switch between a few states (such as calm upward phases and turbulent crises), in each of which returns, volatility and correlations are different. The best-known tool is the hidden Markov model: the state is not directly visible and is estimated from the returns. Here you will learn how the models calculate, what research shows for asset allocation and why a regime can often only be identified with certainty in hindsight.

The idea: markets with several faces

A single mean and a single volatility describe long price series poorly. Years of calmly rising prices alternate with short, violent crises in which volatility jumps and stocks move more closely together (asymmetric correlation). Ang and Timmermann (2012) summarize the research as follows: regime-switching models capture the fact that markets often change their behavior abruptly and that the new behavior then persists for several periods. Means, volatilities, autocorrelations and covariances differ by regime. That is why such models explain fat tails, volatility clustering, skewness and fluctuating correlations.

There are three families. Statistically estimated states, as in the hidden Markov model or Markov switching regression; threshold and break models, in which an observed variable or a point in time triggers the switch; and rule-based regimes derived from macro data or market indicators, such as recession or no recession.

The hidden Markov model

A hidden Markov model (HMM) has three building blocks. First, states S_t that follow a Markov chain: tomorrow's state depends only on today's. Second, the transition matrix with the probabilities of switching from state i to state j. Third, the emission distributions: for each state, a distribution of the observed return, usually a normal distribution with its own mean and volatility. Only the return is observed; the state remains hidden. Rabiner (1989) describes the three basic tasks: calculating the probability of the data, finding the most likely sequence of states and estimating the parameters.

p_ij = P(S_t = j | S_t−1 = i); r_t | S_t = k ~ N(μ_k, σ_k²); π₁ = (1 − p₂₂) / (2 − p₁₁ − p₂₂); Duration_k = 1 / (1 − p_kk)
p_ij
probability of switching from state i to state j; each row of the matrix sums to 1
μ_k, σ_k
mean and volatility of the return in state k
π₁
long-run share of time in state 1 (stationary distribution with two states)
Duration_k
expected number of periods a state lasts once it has begun
Hidden Markov model with two states

Figures from the worked example further below. The expected duration is 1 / (1 − p): 20 months calm, 5 months turbulent. Only the return is observed; the model has to estimate which state the market is in.

Estimation with Baum-Welch and EM

The parameters are usually estimated with the procedure of Baum et al. (1970), now called the Baum-Welch algorithm, a special case of the EM algorithm of Dempster et al. (1977). In the E-step, the forward-backward algorithm uses the current parameters to calculate how likely each state was at each point in time. In the M-step, means, volatilities and transition frequencies are re-estimated, weighted by these probabilities. This repeats until the likelihood barely increases any more. EM only finds a local maximum. Serious applications therefore start from many starting values.

Viterbi, filtering and smoothing: the look-ahead trap

The algorithm of Viterbi (1967) uses dynamic programming to find the single sequence of states with the highest joint probability. To do so, it uses the entire sample. So does the smoothed probability P(S_t = k | all data up to T), described for Markov switching models by Kim (1994). Only the filtered probability P(S_t = k | data up to t) uses exclusively what was known at time t (filtered and smoothed probability).

Charts with colored crisis phases usually show Viterbi paths or smoothed probabilities. There, the crisis often begins exactly at the peak, because the model already knows about the crash that follows. Anyone who derives a trading rule from this has a look-ahead bias. A second source is added when the parameters are estimated with the entire history. An honest test uses only parameters estimated on a rolling basis, filtered probabilities and execution only after the signal.

Worked example: two regimes recalculated

Two regimes produce fat tails

Parameters from the example above. The dashed curves are the two regimes, weighted at 80% and 20%; their sum is more peaked in the middle and has a longer left tail than a normal distribution with the same mean (0.50%) and the same volatility (4.24%).

Hamilton's Markov switching regression

Hamilton (1989) modeled the growth of US gross national product with occasional, discrete shifts in the growth rate, governed by a Markov chain. He provided algorithms with which the unobserved shifts can be inferred and the parameters estimated by maximum likelihood. The shift from positive to negative growth turned out to be a recurrent feature of the US business cycle and could serve as an objective criterion for recessions; a typical recession was associated with a permanent drop of about 3% in the level of gross national product.

In general, a Markov switching regression lets any part of a regression switch by regime: the constant, slopes, autoregression and variance. The HMM for returns is the special case without explanatory variables. The textbook treatment, including the filter, is in Hamilton (1994).

y_t = α_{S_t} + β_{S_t} · x_t + σ_{S_t} · ε_t
S_t
hidden regime, follows a Markov chain
α, β, σ
constant, slope and volatility, with separate values for each regime
ε_t
standard normally distributed shock

Threshold models and structural breaks

In the threshold model (TAR) of Tong and Lim (1980), the regime does not switch randomly but as soon as an observed variable crosses a threshold. If this variable is the series' own lagged value, it is called SETAR (self-exciting). An interest rate spread, for example, can wander like a random walk near its mean and revert only beyond a threshold. The advantage: the regime is observable as soon as the threshold is known. The catch: the threshold is also estimated, usually from the same sample.

A structural break is a change that does not revert: a new monetary policy, a new currency regime, a different market structure. Bai and Perron (1998) developed the theory for estimating and testing multiple break points in regressions, including the question of how many breaks there are. For investors, the difference matters: recurring regimes can be learned from history, while a break makes the history before it partly worthless.

Rule-based regimes and clustering

Many practitioners define regimes directly by rules: recession or no recession, phases of the business cycle clock, quadrants of rising or falling growth and rising or falling inflation (growth-inflation regimes, stagflation), volatility regimes based on the level of the VIX or an inverted yield curve. Such rules are transparent and require no estimation. Their thresholds are set by hand, however, and macro data are published with a delay and revised; Croushore and Stark (2001) show how strongly results depend on this.

Clustering looks for groups of similar observations, such as months with similar returns, volatility and correlation. k-means following Lloyd (1982) assigns each month to the nearest of k centers and recalculates the centers until nothing changes any more. A Gaussian mixture model assigns softly, with probabilities, and is also estimated via EM. Both ignore the order of the months. In this sense, an HMM is a Gaussian mixture with a Markov chain. Without this time structure, clusters often jump back and forth from month to month.

ApproachRegime observable?Recurring?Typical problem
Hidden Markov, Markov switchingno, only probabilitiesyesdelayed detection, number of states
Threshold model (TAR, SETAR)yes, once the threshold is fixedyesthreshold estimated from the same sample
Structural breakonly with certainty in hindsightnobreaks at the end of the data hardly detectable
Rule-based (macro, volatility)yes, with a publication lagyesthresholds set by hand, revisions
Clustering (k-means, Gaussian mixture)yes, per observationyesno time structure, frequent switches

Advanced: states, parameters, estimation error

  • Number of states: every additional state increases the likelihood. Information criteria such as the AIC following Akaike (1974) and the BIC following Schwarz (1978) penalize the additional parameters. The usual likelihood ratio test does not apply here, because the parameters of the second state are not even defined under the null hypothesis of a single state.
  • Parameters grow quickly: an HMM with K normally distributed states for one return has K² − K transition, 2K distribution and K − 1 starting parameters: 7 with two, 14 with three and 23 with four states. For five assets with a full covariance matrix, there are already 68 with three states.
  • Rare regimes, uncertain duration: if you observe five switches back to calm times in 25 crisis months, you estimate p₂₂ = 1 − 5 / 25 = 0.80. With a standard error of about 0.08, the expected duration lies between 3.6 and 8.3 months if you go just one standard error down and up.
  • Instability: new data change earlier smoothed regimes, and when re-estimating, states can swap places (label switching). Some solutions are degenerate, such as a state that explains only a single outlier.
  • Time-varying parameters: Nystrup et al. (2015) let the parameters themselves drift slowly, so that the model adapts to new market phases without needing a separate state for each one.

What the research shows

  • International allocation: Ang and Bekaert (2002) model the opportunities of a US investor with regimes in which correlations and volatilities rise in bad times. International diversification nevertheless remains valuable, and currency hedging brings additional benefits. The costs of ignoring regimes are small for pure equity portfolios but rise when a conditionally risk-free asset can be held.
  • Stocks and bonds: Guidolin and Timmermann (2007) need four regimes (crash, slow growth, bull market, recovery) to capture stock and bond returns jointly. The optimal weights differ strongly by state: in the crash state, the equity allocation of a buy-and-hold investor rises with the investment horizon; in the bull market, it falls. Ignoring regimes is costly, and out-of-sample forecasts support the practical value.
  • Dynamic strategies: Kritzman et al. (2012) estimate Markov switching models for market turbulence, inflation and growth. A dynamic allocation based on them beat the static one in the backtest, especially for investors who want to avoid large losses.
  • Letting the data speak: using a world equity index and a world government bond index, Nystrup et al. (2015) show that a static portfolio need not be optimal even without any forecasting skill. Nystrup et al. (2018) combine HMM forecasts of the mean and variance with model predictive control and achieve a higher return at significantly lower risk than buy and hold in several major equity indices. This holds after transaction costs, with a one-day delay and with non-interest-bearing cash as the only alternative. A penalty term for frequent trading made the procedure more robust.

For context: the favorable results come mostly from the authors' own backtests. The number of states, data frequency and period were chosen with knowledge of history. In our assessment, evidence of such models succeeding in real time over many years is rare. More on this under backtest overfitting.

Limits and common mistakes

  • Detection in hindsight: a regime only becomes likely after a few observations, as the worked example shows. By the time it is certain, part of the loss has often already occurred. This is the same problem as with trend following and market timing.
  • Look-ahead: smoothed probabilities, Viterbi paths, parameters estimated with the entire history and revised macro data give away the future.
  • Overfitting: the number of states, data frequency, assets and estimation window are all adjustable. Anyone who tries many combinations will always find a model that elegantly predicts the financial crisis.
  • Few crises: a handful of switches is not enough to estimate transition probabilities accurately.
  • Volatility yes, returns hardly: turbulent regimes can be identified fairly well through volatility. Whether they also have a lower expected return is much harder to prove (see forecasting models).

This article explains methods and is not investment advice.

How Portfolio Lab calculates it

An estimated hidden Markov model is shown on the Regime page. For a price series (one of the 30 markets on the Bubbles page or your own ticker), it estimates Gaussian HMMs with one to four regimes on log returns of completed weeks or months, using the Baum-Welch algorithm with five starting values and a fixed seed. The regimes are sorted by volatility and, with two regimes, are called “Calm” and “Turbulent”. The page shows filtered and smoothed probabilities, since when the Viterbi path has been in the latest regime, the mean, volatility, share of time and expected duration of each regime, the transition matrix and log L, AIC and BIC for each number of regimes; Auto picks the smallest BIC among two to four regimes. It is a retrospective: parameters and smoothed probabilities use the entire history. This is exactly the look-ahead trap described above, and a note on the page points it out.

The Regime (HMM) tactical model on the Tactical page calculates without look-ahead: it first estimates the parameters after five years of weekly returns (ten years for monthly returns), then re-estimates them annually with all data up to that point, and at each month-end uses only the filtered probability of the regime with the highest volatility. If it is above the threshold (default 50%), the base portfolio moves entirely into the fallback asset; alternatively, 1 − P(Turbulent) is held in the base portfolio. The comparison is with buy and hold. The details are in the regime methodology.

The Macro page does not estimate a hidden Markov or Markov switching model but classifies each month by fixed rules, for the US, the euro area and Germany. There are six types: Recession (the US by the official dating, the euro area and Germany from two consecutive quarters of falling real GDP), Business cycle clock (indicator smoothed over three months, above or below the neutral value and rising or falling compared with three months earlier: Recovery, Expansion, Slowdown, Downturn), Inflation in four bands (below 0%, 0–2%, 2–4%, above 4%), Rate phases (money market rate compared with six months earlier, with a threshold of ±0.25 percentage points), Yield curve (inverted below 0, flat below 0.5 percentage points, otherwise normal) and Growth and inflation in four quadrants: Goldilocks, Reflation, Stagflation, Cooling.

For your portfolios, the regime analysis shows, for each state, the number of months, the share of time, the return p.a. as a geometric mean, the volatility, the share of positive months and the worst month. The regimes are determined in hindsight with the data available today, including later revisions. With the Lag setting of 0 to 24 months, a regime only applies that many months later. This replicates the publication delay, not the revisions (macro methodology).

A rule-based volatility regime is provided by the Volatility barometer on the Volatility dashboard: the mean of the percentile ranks of seven components over three years, divided into five zones from “very calm” to “stress” (methodology). Portfolio Lab does not offer estimated threshold models (TAR), tests for structural breaks or clustering. The regime analysis on the Macro page is descriptive, and the Regime page is a retrospective. Only the tactical model provides a trading signal without look-ahead, and even that is not investment advice.

Frequently asked questions

What is a hidden Markov model in simple terms?

A model in which the market switches between a few hidden states, such as calm and turbulent. Each state has its own return distribution, and a transition matrix determines how likely a switch is. From the observed returns, the model estimates which state the market is probably in at the moment.

How long does a market regime last on average?

With a probability p of remaining in the state, the expected duration is 1 / (1 − p) periods. With p = 0.95 per month, that is 20 months; with p = 0.80, only 5 months.

Can regime models predict crashes?

Hardly. The models only detect a turbulent regime after a few weak or highly volatile periods have occurred. Charts that color crises from exactly the peak onwards usually use smoothed probabilities, which already know the future.

What is the difference between filtered and smoothed probabilities?

The filtered probability uses only data up to the respective point in time and is therefore available in real time. The smoothed probability uses all data up to the end of the sample. For backtests, only the filtered probability is admissible.

How many regimes do you need?

Many studies work with two or three states for a single return; for stocks and bonds together, Guidolin and Timmermann found four. More states improve the in-sample fit but increase the number of parameters and the risk of overfitting. Information criteria such as the BIC help with the choice.

What is the difference between Markov switching and a structural break?

Markov regimes recur, such as upswing and recession. A structural break is a one-off change after which the old parameters no longer apply.

Literature

  1. Akaike, H. (1974): A new look at the statistical model identification. IEEE Transactions on Automatic Control 19 (6), pp. 716–723. doi:10.1109/tac.1974.1100705
  2. Ang, Andrew; Bekaert, Geert (2002): International Asset Allocation With Regime Shifts. Review of Financial Studies 15 (4), pp. 1137–1187. doi:10.1093/rfs/15.4.1137
  3. Ang, Andrew; Timmermann, Allan (2012): Regime Changes and Financial Markets. Annual Review of Financial Economics 4 (1), pp. 313–337. doi:10.1146/annurev-financial-110311-101808
  4. Bai, Jushan; Perron, Pierre (1998): Estimating and Testing Linear Models with Multiple Structural Changes. Econometrica 66 (1). doi:10.2307/2998540
  5. Baum, Leonard E.; Petrie, Ted; Soules, George; Weiss, Norman (1970): A Maximization Technique Occurring in the Statistical Analysis of Probabilistic Functions of Markov Chains. The Annals of Mathematical Statistics 41 (1), pp. 164–171. doi:10.1214/aoms/1177697196
  6. Croushore, Dean; Stark, Tom (2001): A real-time data set for macroeconomists. Journal of Econometrics 105 (1), pp. 111–130. doi:10.1016/S0304-4076(01)00072-0
  7. Dempster, A. P.; Laird, N. M.; Rubin, D. B. (1977): Maximum Likelihood from Incomplete Data Via the EM Algorithm. Journal of the Royal Statistical Society Series B: Statistical Methodology 39 (1), pp. 1–22. doi:10.1111/j.2517-6161.1977.tb01600.x
  8. Guidolin, Massimo; Timmermann, Allan (2007): Asset allocation under multivariate regime switching. Journal of Economic Dynamics and Control 31 (11), pp. 3503–3544. doi:10.1016/j.jedc.2006.12.004
  9. Hamilton, James D. (1989): A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle. Econometrica 57 (2), pp. 357–384. doi:10.2307/1912559
  10. Hamilton, James D. (1994): Time Series Analysis. Princeton University Press.
  11. Kim, Chang-Jin (1994): Dynamic linear models with Markov-switching. Journal of Econometrics 60 (1–2), pp. 1–22. doi:10.1016/0304-4076(94)90036-1
  12. Kritzman, Mark; Page, Sébastien; Turkington, David (2012): Regime Shifts: Implications for Dynamic Strategies. Financial Analysts Journal 68 (3), pp. 22–39. doi:10.2469/faj.v68.n3.3
  13. Lloyd, S. (1982): Least squares quantization in PCM. IEEE Transactions on Information Theory 28 (2), pp. 129–137. doi:10.1109/tit.1982.1056489
  14. Nystrup, Peter; Hansen, Bo William; Madsen, Henrik; Lindström, Erik (2015): Regime-Based Versus Static Asset Allocation: Letting the Data Speak. The Journal of Portfolio Management 42 (1), pp. 103–109. doi:10.3905/jpm.2015.42.1.103
  15. Nystrup, Peter; Madsen, Henrik; Lindström, Erik (2018): Dynamic portfolio optimization across hidden market regimes. Quantitative Finance 18 (1), pp. 83–95. doi:10.1080/14697688.2017.1342857
  16. Rabiner, L. R. (1989): A tutorial on hidden Markov models and selected applications in speech recognition. Proceedings of the IEEE 77 (2), pp. 257–286. doi:10.1109/5.18626
  17. Schwarz, Gideon (1978): Estimating the Dimension of a Model. The Annals of Statistics 6 (2), pp. 461–464. doi:10.1214/aos/1176344136
  18. Tong, H.; Lim, K. S. (1980): Threshold Autoregression, Limit Cycles and Cyclical Data. Journal of the Royal Statistical Society Series B: Statistical Methodology 42 (3), pp. 245–268. doi:10.1111/j.2517-6161.1980.tb01126.x
  19. Viterbi, A. (1967): Error bounds for convolutional codes and an asymptotically optimum decoding algorithm. IEEE Transactions on Information Theory 13 (2), pp. 260–269. doi:10.1109/tit.1967.1054010

Full bibliography

This article explains a method; it is not investment or tax advice. Worked examples are simplified and rounded. All terms in the glossary.