Skip to main content

HMM Regime Detection

Hidden Markov Model — latent market regimes (risk-on/off, high/low vol)


Overview

  • Model ID: hmm-regime
  • Framework: hmmlearn (GaussianHMM)
  • Best for: Detecting latent market regimes as a feature for other models
  • GPU required: No (CPU-only)
  • Specialist: forecasting (analyze mode)

An unsupervised Hidden Markov Model learns latent regimes from returns/volatility features. At inference it decodes a feature sequence into a regime path and returns the current regime, the most likely next regime, the full transition matrix and per-state statistics. The regime label is a powerful conditioning feature for every other model.


When to Use

Perfect for:

  • Risk-on / risk-off and high/low-volatility regime detection
  • Producing a regime feature to condition forecasters or sizing
  • Change-of-state awareness in a strategy

Not ideal for:

  • Producing a numeric point/volatility forecast (use GARCH/HAR/ARIMA)

Quick Start

job = client.training.create(
model="hmm-regime",
dataset_id=dataset.id,
hyperparameters={"n_components": 3, "feature_columns": ["ret", "vol"]},
)
job.wait()

Dataset Format

One or more numeric feature columns (returns, volatility, etc.), plus an optional date column:

ds,ret,vol
2022-01-01,-0.0034,0.011
2022-01-02,0.0012,0.010
...

Leave feature_columns empty to use all numeric columns. Requirements:n_components × 10 observations.


Hyperparameters

ParameterDefaultDescription
n_components3Number of latent regimes
covariance_type"diag"spherical / diag / full / tied
n_iter200Max EM iterations
returns_from_pricesfalseUse pct_change of the feature columns
feature_columns[]Feature columns (empty = all numeric)
date_column""Timestamp column (empty = auto-detect)

Inference (analyze mode)

Provide the recent feature sequence in series; the result carries the structured regime output in the generic payload envelope (forecasts holds the decoded state path):

result = client.endpoints.infer(endpoint_id=ep, input_data={
"series": {"ret": [...], "vol": [...]}
})
{
"model_type": "hmm",
"payload": {
"current_regime": 0,
"expected_next_regime": 1,
"n_states": 3,
"state_probabilities": [0.92, 0.05, 0.03],
"transition_matrix": [[...], [...], [...]]
}
}