Lesson 04
A Hidden Markov Model has three components: initial probabilities, a transition matrix, and emission distributions. Together they define a complete probability model of how hidden market regimes generate observable returns.
The key insight of the HMM: the market's true state (Bull Run, Bear, Chop) is hidden. We never observe it directly. What we do observe is the return at each time step — the HMM must infer the hidden state from the observable data.
An HMM is fully defined by three sets of parameters, collectively written as λ (lambda).
Probability of starting in each state. A vector of length K (7 for our model). Sums to 1.
K×K matrix. A[i][j] = P(state j at t+1 | state i at t). Each row sums to 1.
One multivariate Gaussian per state. B(x|k) = N(x; μ_k, Σ_k). Probability of observing features x while in state k.
Each cell A[i][j] is the probability of moving from regime i to regime j on the next bar. High values on the diagonal mean regimes are sticky — once you're in a Bull Run, you tend to stay there.
Click "Simulate" to watch the HMM generate a sequence: it samples from π to choose a starting state, then emits an observation from that state's Gaussian, then transitions to a new state using the transition matrix, and repeats.