regime_features¶
Defined in fynance.features.regime
- regime_features(X, w=21, period=252)[source]
Build the causal regime feature matrix: trailing vol and mean return.
Both columns use trailing windows (past only), so the matrix is causal — the value at
tdepends onX[:t+1]only.- Parameters:
- Xnp.ndarray
One-dimensional price/level series.
- wint
Rolling window.
- periodint
Annualization factor for the volatility column.
- Returns:
- np.ndarray
Shape
(len(X), 2)—[realized_volatility, rolling_mean_log_return].
Notes
Row
0is a deterministic warmup point: there is no prior observation, so both the realized volatility and the mean log-return are0(an artificially “ultra-calm” point). It is kept so the matrix stays aligned withX; callers fitting a clustering on the matrix may wish to drop or mask this row.