Using Hidden Markov Models for Crypto Regime Detection
Most market regime classifiers use simple threshold rules: SMA above 200 = bull, below = bear. These work but they're noisy and laggy. Hidden Markov Models (HMMs) offer a probabilistic alternative that can detect regime transitions 6-12 hours earlier.
Here's how we built one.
Why HMMs for Regime Detection
Markets transition between regimes (bull/bear/chop) without announcing it. You can observe symptoms — volatility changes, funding rate shifts, sentiment swings — but the underlying regime is hidden. This is exactly what HMMs are designed for: inferring hidden states from observable emissions.
Architecture
Our HMM has:
- 3 hidden states: Bull, Bear, Chop
- 6 observations: SMA ratio, volatility ratio, funding rate, fear/greed, volume level, BTC dominance
- Training: Baum-Welch algorithm on 3,291+ market snapshots
- Inference: Viterbi algorithm for most likely state sequence
The Observations
Each observation is discretized from continuous market data:
``python
Simplified observation generation
def make_observation(snapshot):
return {
'sma_ratio': 'bullish' if snapshot.sma50 > snapshot.sma200 else 'bearish',
'volatility': 'high' if snapshot.atr20/snapshot.atr90 > 1.3 else 'low',
'funding': 'positive' if snapshot.funding_rate > 0.01 else 'negative' if snapshot.funding_rate < -0.01 else 'neutral',
'fear_greed': 'greed' if snapshot.fg > 60 else 'fear' if snapshot.fg < 40 else 'neutral',
'volume': 'high' if snapshot.volume_ratio > 1.2 else 'low',
'dominance': 'rising' if snapshot.btc_dom_delta > 0.5 else 'falling' if snapshot.btc_dom_delta < -0.5 else 'flat',
}
`
Training with Baum-Welch
The Baum-Welch algorithm (a special case of EM) estimates the transition and emission probabilities:
`
Transition matrix (what we learned):
→ Bull → Bear → Chop
Bull: [ 0.017 0.821 0.162 ]
Bear: [ 0.012 0.935 0.053 ]
Chop: [ 0.089 0.456 0.455 ]
`
Key finding: Bear states are extremely sticky (93.5% self-transition probability). Once the market enters a bear regime, it tends to stay there. Bull detections are transient (1.7% stay probability) — the HMM is detecting bounces within bear markets rather than true regime shifts.
Results vs Weighted Classifier
We compared the HMM against our 10-signal weighted ensemble:
| Metric | HMM | Weighted Ensemble |
|---|---|---|
| Agreement rate | 68.4% | — |
| Bear detection | Earlier by 6-12h | More stable |
| Bull detection | Noisy (false positives) | More reliable |
| Chop detection | Poor (rare state) | Better (threshold-based) |
The HMM excels at detecting transitions early. The weighted ensemble excels at steady-state classification. We use both:
Weighted ensemble → primary regime classification (what the API returns)
HMM → early warning signal for upcoming transitions (available in intelligence brief)
Accessing the HMM
The HMM regime is available via the Regime API (Pro tier):
`bash
curl -H "Authorization: Bearer YOUR_KEY" \
https://getregime.com/api/v1/intelligence/hmm-regime
`
Returns:
`json
{
"hmmRegime": "bear",
"hmmConfidence": 0.89,
"weightedRegime": "bear",
"agreement": true,
"transitionProbability": 0.065,
"lastRetrained": "2026-03-26T04:00:00Z"
}
`
When
agreement is false, a regime transition may be imminent. The transitionProbability indicates how likely the current regime is to change in the next evaluation window.
Key Takeaways
HMMs detect transitions earlier but have more false positives in steady state
Bear states are sticky — once bear, 93.5% chance of staying bear
Bull "detections" are often bounces — the HMM finds temporary rallies within larger bear trends
Combining HMM + threshold classifier gives the best of both worlds
Free regime endpoint (weighted ensemble):
curl https://getregime.com/api/v1/market/regime`
Full intelligence including HMM: Pro tier
GitHub: getregime.com