ml4t-compute-features
Installation
SKILL.md
Compute Features
Computing features across a panel of assets requires group-aware operations - a global rolling mean mixes Apple's history with Tesla's. Every windowed statistic must be computed per symbol.
The Problem
Features computed with global statistics bleed information across assets. A z-score computed over the full dataframe uses one symbol's volatility to normalize another. Worse, using .mean() on the full column leaks future data from late-arriving symbols into early rows.
The Pattern
WRONG
import polars as pl
# Global statistics mix symbols and leak future
df = df.with_columns(
mom_zscore=(pl.col("returns") - pl.col("returns").mean())
/ pl.col("returns").std()
)