A hidden Markov model, or HMM, assumes that a system moves between a small number of unobserved states, such as calm and turbulent markets, and that what we observe, like returns, depends on the current state. The model estimates which state the market is in.
The building blocks
- Hidden states: for example, state 1 is a calm, rising market and state 2 a volatile, falling one.
- Transition probabilities: the chance of moving from one state to another each period.
- Emission distributions: the pattern of returns, such as the mean and volatility, in each state.
An illustrative example
| From \ To | State 1 (calm) | State 2 (turbulent) |
|---|---|---|
| State 1 | 0.95 | 0.05 |
| State 2 | 0.10 | 0.90 |
If the chance of staying in state 1 each week is 0.95, the expected stay is 1 / (1 - 0.95) = 20 weeks. For state 2 it is 1 / (1 - 0.90) = 10 weeks. The probabilities are made up for illustration.
Fitting and using it
The parameters are estimated from the data, commonly with the Baum-Welch (expectation-maximisation) algorithm. Two outputs matter:
- Filtered probabilities use data up to each date only, so they can be used in real time.
- Smoothed probabilities use the whole sample and look much better in hindsight, but they contain look-ahead bias if used for trading decisions in a test.
Cautions
- States are unstable. Estimates can change when new data arrive, and states can swap labels.
- Number of states. Each extra state gives fewer observations to learn from, which invites overfitting.
- Lag. Regime changes are usually recognised only after they have started.
HMMs are one approach to the problem described under regime detection models and market regimes.
Frequently asked questions
What is a hidden Markov model?
It is a statistical model in which an unobserved state moves between a few possibilities over time according to fixed probabilities, and the observed data depend on the current state.
How are hidden Markov models used in finance?
They are used to infer market regimes, such as calm and turbulent periods, from returns and other data, and to estimate how likely a switch is.
What is the difference between filtered and smoothed probabilities?
Filtered probabilities use only data up to the current date and can be used live. Smoothed probabilities use the whole sample and are not available at the time, so using them in a backtest leaks the future.
Can a hidden Markov model predict the next regime?
It gives probabilities of moving between states, but regime changes are hard to anticipate and are usually recognised with a delay.