PROJECTS ·
HMM Market Regime Detection
A Gaussian hidden Markov model (HMM) is used to label market regimes for SPY, based on daily prices from January 2010 to November 2025. Four features are computed for each day: the 5-day return, 20-day volatility, the deviation from the 60-day moving average, and 20-day downside volatility. Each feature is z-scored over the 252 days ending that day. No later data therefore enters the scaling. The model is fitted on the 2,962 days before 2023, and the number of states is chosen by BIC between 2 and 5. However, BIC fell at every step, so 5 is the upper limit of the search rather than a clear optimum. The states are named by mean volatility. For every day, the state is obtained by forward filtering, which uses only the observations available up to that day and never looks at the rest of the series.
The states are evaluated through a one-day 95% VaR. For each state, the VaR is set to the 5th percentile of training-period returns on the days that follow it, and the VaR for day t is taken from the filtered state of day t-1. Ten assets are tested from January 2023 to December 2025, which gives 752 trading days, or 1,096 days for bitcoin. The SPY model is compared with seven asset-class models, each fitted on a basket of two to five tickers before 2023. The asset-class models come closer to the nominal 5% on 7 of the 10 assets. However, the gain is small. The mean absolute gap is reduced only from 1.90 to 1.84 percentage points, and both the Kupiec and Christoffersen tests are passed on just 3 assets by each approach. For EFA, EEM, AAPL and bitcoin, violation rates stay between 1.3% and 3.1% under both models, so the VaR is too conservative for these assets.