The Danger of Static Models
A quantitative trading strategy that works beautifully in a low-volatility, mean-reverting bull market will obliterate your portfolio during a high-volatility momentum crash. Statistical models must be regime-aware.
Regime Classification with HMMs
We implemented a Gaussian Hidden Markov Model (HMM) using the hmmlearn library to classify the market into 3 hidden states (e.g., Low Vol Bull, High Vol Bear, Choppy) based on recent returns, realized variance, and bid-ask spread data.
from hmmlearn import hmm
import numpy as np
# Features: Daily returns and daily volatility
X = np.column_stack([returns, volatility])
# Train a 3-state Hidden Markov Model
model = hmm.GaussianHMM(n_components=3, covariance_type="full", n_iter=100)
model.fit(X)
# Predict the current hidden market regime
hidden_states = model.predict(X)Our downstream execution algorithms now dynamically adjust their aggressiveness based on the HMM's predicted state. If the HMM detects a transition to a "High Volatility" regime, the system automatically widens our quoting spreads and slashes our inventory limits.