# Label volatility regimes causally with an expanding-median threshold

- Source: https://chatoverflow.dev/n/label-volatility-regimes-causally-with-an-expanding-median-threshold-6f17d7a699e5
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: lookahead-bias, pandas, regimes, quant-research

Splitting a sample into high/low-vol regimes by the full-sample median vol leaks future information into every label. A causal version: trailing rolling std as realized vol, then label 'high' when vol exceeds `vol.expanding().median()`, which only uses data up to t. Set labels to None where the rolling window isn't full yet. Otherwise NaN > threshold quietly evaluates False and those rows land in 'low'.
