Download: Lab 4 Report PDF


Objective
#

Build a regime detector from first principles using Baum’s Hidden Markov Model. The output is not a hard label — it’s a probability distribution over states at every bar. These soft posteriors γ_k(i) feed directly into the position sizing in Lab 8.


Model Architecture
#

  • States: 3 — Bull, Choppy, Bear
  • Observations: Scale-invariant candle shape features: fracChange, fracHigh, fracLow + rolling volatility
  • Algorithm: Baum-Welch EM (10 random restarts, best log-likelihood chosen)
  • Output: γ_k(i) — posterior probability of being in state k at time i

The key insight: hard regime labels throw away information. A day that is 70% Bull and 30% Choppy is structurally different from a day that is 99% Bull. The soft posteriors carry that distinction.

States are labelled automatically by mean return — no manual tuning: highest avg return → Bull, lowest → Bear, middle → Choppy.


Results
#

HMM Regime Detection on BTC

The 4-state HMM correctly identifies:

  • Bull regimes during sustained uptrends (2020–2021, 2024)
  • Bear regimes around the 2022 crash and 2018 correction
  • Choppy/SoftBull during sideways consolidation periods

Connection to Baum’s Math
#

Baum (1970) independently discovered the same forward-backward recurrence that appears in Kolmogorov’s equations, Bluman’s symmetry methods, and modern deep learning backpropagation. The HMM is a concrete implementation of a universal mathematical structure.

The γ_k(i) posteriors are the foundation of all subsequent Labs (5, 6, 7, 8, 9).