# Markov regime model: how regime switching works in markets

> How Markov chains and hidden Markov models describe calm and stormy market regimes, what Hamilton's model showed, and simpler rules you can test.

Written by [Tactfolio research team](https://tactfolio.com/about/editorial-policy.md), published 2026-10-16, updated 2026-10-16.

A Markov regime model treats the market as switching between a few hidden "moods", such as a calm rising market and a stormy falling one. It estimates how likely each mood is today and how likely the market is to switch tomorrow. Traders use these models to decide when to take more risk or less, but the moods are only clear in hindsight.

## Key points

- A **regime** is a stretch of time when markets behave in a similar way, such as calm and rising or wild and falling.
- A **Markov chain** says the chance of moving to the next regime depends only on the regime you are in now.
- A **hidden Markov model** adds that you cannot see the regime directly. You guess it from returns.
- James Hamilton's 1989 paper made this approach popular in economics.
- Simple rules, like trend filters and "canary" assets, try to answer the same question with less math.

## What is a market regime?

A market regime is a period when prices behave in a fairly steady way, different from other periods. Spotting regimes is a common goal in [algorithmic trading](https://tactfolio.com/learn/algorithmic-trading.md). The simplest split has two regimes:

| | Calm bull | Volatile bear |
| --- | --- | --- |
| Prices | Tend to rise | Tend to fall |
| Daily swings | Small | Large |
| Stocks and other assets | Move more on their own | Often fall together |
| How long it lasts | Often years | Often months |

The last two rows matter most for investors. Ang and Bekaert found that bear markets come with higher swings and with stocks in different countries moving together more ([NBER](https://www.nber.org/papers/w10080)). So spreading money across countries helps least right when you need it most.

## How does a Markov chain work?

A Markov chain is a model where tomorrow's state depends only on today's state, not on the longer past. It is described by a **transition table**: the chance of moving from each state to each other state.

Here is a made-up example with round numbers. Each row is where the market is this month. Each column is where it goes next month.

| This month | Next month: calm bull | Next month: volatile bear |
| --- | --- | --- |
| Calm bull | 95% | 5% |
| Volatile bear | 20% | 80% |

Read the first row like this: if the market is calm now, there is a 95% chance it stays calm next month and a 5% chance it turns stormy.

This small table tells you a lot:

- **How long regimes last.** A 5% chance of leaving each month means a calm stretch lasts about 20 months on average (1 divided by 0.05). A stormy one lasts about 5 months (1 divided by 0.20).
- **How much time each regime gets.** Over the long run, this market is calm about 80% of the time and stormy about 20%.
- **Regimes are sticky.** Today's mood is the best single guess for next month's mood.

These numbers are an example only. Real tables come from fitting a model to data, and they change a lot with the data you pick.

## What is a hidden Markov model in trading?

A hidden Markov model is a Markov chain where you cannot see the state. You only see returns, and you work backward to guess which state probably produced them.

Say the model has learned two things. Calm months tend to bring returns near +1% with small swings. Stormy months tend to bring returns near −2% with big swings. Then a month with a −6% return makes the stormy state much more likely. A quiet +1% month makes the calm state more likely.

The model never says for sure that a bear market has started. Instead it gives a chance, such as a 70% chance of the stormy state. A trading rule then turns that into an action. For example, it might cut stocks to half whenever the stormy chance is above 50%.

## Where did regime-switching models come from?

The modern approach comes from economist James Hamilton. In 1989 he published "A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle" in *Econometrica* ([Econometric Society](https://www.econometricsociety.org/publications/econometrica/1989/03/01/new-approach-economic-analysis-nonstationary-time-series-and)). He modeled US economic growth as switching between a growing state and a shrinking state that nobody sees directly. His model's shifts from growth to decline lined up with US recessions so well that he suggested they could help define them.

Finance researchers then used the same idea for investing. Andrew Ang and Geert Bekaert built regime-switching models for asset allocation, which means deciding how much to put in stocks, bonds and cash. In their 2003 study, choosing between stocks, bonds and cash by regime added real value. When a lasting bear market hit, the model moved mostly to cash ([NBER](https://www.nber.org/papers/w10080)). Their work was later published in the *Financial Analysts Journal* in 2004.

## What are the limits of Markov regime models?

The biggest limit is timing. A model learns that the regime changed only after some bad months have already happened. By then part of the loss is done.

Other problems:

- **Hindsight looks perfect.** When you fit a model on 30 years of data, it "knows" where every crash was. In real time, its guesses are much less sure.
- **Many choices.** Two regimes or three? Monthly data or daily? Each choice changes the answer, and each one is a chance to fit noise. Our guide to [backtesting](https://tactfolio.com/learn/backtesting-explained.md) explains why that matters.
- **Whipsaws.** If the model flips often, you trade often, pay costs and can sell near lows.
- **The past may not repeat.** The table is fitted on history. A new kind of crisis can behave differently.

## Simpler regime rules you can test

You do not need a hidden Markov model to ask whether the market is calm or stormy. Many classic strategies use plain rules that act as rough regime signals.

**Trend filters.** A fund above its long-term average is treated as "calm." Below it is treated as "stormy." This is the core of [trend following](https://tactfolio.com/learn/trend-following.md). The [Faber 10-month moving average](https://tactfolio.com/strategies/faber-10-month-moving-average.md) rule holds the S&P 500 above its 10-month average and Treasury bills below it.

**Canary assets.** Some assets tend to weaken early in a sell-off, like a canary in a coal mine. [Defensive Asset Allocation](https://tactfolio.com/strategies/defensive-asset-allocation.md) watches emerging-market stocks and US bonds. When one weakens, it moves half of the money to safer bonds. When both weaken, it goes fully defensive. [Vigilant Asset Allocation](https://tactfolio.com/strategies/vigilant-asset-allocation.md) goes fully defensive if even one of its four assets turns negative.

**Economic data.** [Growth-Trend Timing with unemployment](https://tactfolio.com/strategies/growth-trend-timing-unemployment.md) leaves the S&P 500 only when two warnings agree. The unemployment rate must be above its 12-month average, and the index must be below its 10-month average. The [original Growth-Trend Timing](https://tactfolio.com/strategies/growth-trend-timing.md) uses retail sales and industrial production instead.

These rules are cruder than a Markov model, but you can read every step. Many [tactical asset allocation](https://tactfolio.com/learn/tactical-asset-allocation.md) strategies are built this way.

## Try it on Tactfolio

Tactfolio's builder cannot run a Markov or hidden Markov model today. It has no block that estimates hidden states or transition chances. What you can build in the [strategy builder](https://tactfolio.com/builder) are the simpler regime rules above. These include trend filters, canary checks and conditions on US economic data from FRED. Our guide to [common patterns](https://tactfolio.com/docs/patterns.md) shows how trend filters and canaries are built. Open any of the classic strategies linked above to see the rules, then copy one and change a signal. Every backtest is hypothetical and uses daily prices.

## Common questions

### What is a hidden Markov model in trading?

It is a model that assumes the market switches between a few unseen states, such as calm and stormy. It uses past returns to estimate the chance of being in each state today. A trading rule then changes how much risk to take based on those chances.

### Do Markov regime models predict crashes?

No. They estimate which regime the market is probably in now, using data that has already happened. They tend to recognize a stormy regime after it has started, not before.

### What is a regime switching model?

A regime switching model is any model where the rules of the data change between a few states. Each state has its own average return and size of swings. Hamilton's 1989 Markov switching model is the best-known example.

### How many regimes should a model have?

Most investing studies use two or three. More regimes fit the past better but are harder to estimate and easier to overfit. Two regimes, calm and stormy, is a common place to start.

### Can I build a Markov model in Python?

Yes. Statistics libraries such as [statsmodels](https://www.statsmodels.org/stable/examples/notebooks/generated/markov_regression.html) include Markov switching models. Fitting one takes only a few lines of code. Testing it honestly, on data it was not fitted on, is the hard part.

## The details

In a two-state chain with a chance *p* of leaving state 1 and a chance *q* of leaving state 2 each period, the average stay in state 1 is 1/*p* periods. The long-run share of time in state 1 is *q* / (*p* + *q*). In the example above, *p* = 0.05 and *q* = 0.20, so the calm share is 0.20 / 0.25 = 80%.

A hidden Markov model adds an output rule for each state, often a normal distribution of returns with its own mean and volatility. The model is usually fitted by maximum likelihood. A filter then updates the chance of each state as each new return arrives. Using "smoothed" chances, which look at the whole sample, in a backtest is a form of look-ahead bias.

## Put it into practice

- [Quant trading](https://tactfolio.com/quant-trading.md): An algo trading platform for daily rules: build them from blocks, backtest with costs and reality checks, and run them in Alpaca.
- [Backtesting](https://tactfolio.com/backtesting.md): Free backtesting software for stocks, ETFs, and crypto perps.

## Sources

- [A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle](https://www.econometricsociety.org/publications/econometrica/1989/03/01/new-approach-economic-analysis-nonstationary-time-series-and), James D. Hamilton, Econometrica 57(2), 1989, The Econometric Society, accessed 2026-10-16
- [How Do Regimes Affect Asset Allocation?](https://www.nber.org/papers/w10080), Andrew Ang and Geert Bekaert, NBER Working Paper 10080, 2003, accessed 2026-10-16
- [Markov switching dynamic regression models](https://www.statsmodels.org/stable/examples/notebooks/generated/markov_regression.html), statsmodels documentation, accessed 2026-10-16
- [Defensive Asset Allocation (DAA)](https://tactfolio.com/strategies/defensive-asset-allocation), Tactfolio, accessed 2026-10-16
- [Growth-Trend Timing with unemployment (GTT-UE)](https://tactfolio.com/strategies/growth-trend-timing-unemployment), Tactfolio, accessed 2026-10-16
