Market regime

Unsupervised market-regime labelling by clustering rolling volatility / return features (built by regime_features). detect_regimes is the in-sample convenience (for analysis only — it sees the whole series).

For backtests use RegimeDetector, the causal variant: fit clusters on the train window only, then predict assigns each later bar to its nearest centroid online — no future information leaks into a label. Use the resulting regime as a feature column in the X matrix you pass to a strategy (see Strategy (fynance.strategy) and Research workflow).

detect_regimes(X[, n_regimes, w, period, seed])

Label market regimes by k-means on rolling vol / return features.

regime_features(X[, w, period])

Build the causal regime feature matrix: trailing vol and mean return.

RegimeDetector([n_regimes, w, period, seed])

Causal market-regime detector (fit on the past, assign online).