Feature Engineering for Finance
Building predictive features from financial data without destroying signal, the stationarity-versus-memory tradeoff, fractional differentiation, and detecting structural breaks.
Prerequisites: Ordinary Least Squares (OLS), Look-Ahead Bias
Feature engineering in finance is caught between two requirements that pull in opposite directions. Statistical learning wants stationary inputs, features drawn from a stable distribution, so that what the model learns on the past applies to the future. But the raw series that carry the most predictive memory, prices, cumulative volumes, spreads, are non-stationary. The central craft is transforming data enough to be stationary while destroying as little memory as possible, and doing it all without leaking the future. Get this wrong and even a powerful model like a gradient-boosted forest learns nothing that generalizes.
The stationarity–memory tradeoff
A stationary series has a mean, variance, and autocovariance that do not change over time. Prices are the opposite: a price level is unbounded, trending, and drifting, a model trained on prices from $10–$50 has no idea what to do at $500. The textbook fix is integer differencing: work with returns, (in logs). Returns are roughly stationary, but a first difference erases almost all memory. The return series is nearly serially uncorrelated by construction, so any long-horizon predictive structure (a slow trend, a persistent valuation gap) has been differenced away. You have bought stationarity by throwing out the signal.
This is the tension: raw prices are all memory and no stationarity; returns are all stationarity and no memory. The right answer is usually in between.
Fractional differentiation
López de Prado's tool for the middle ground is fractional differentiation: apply the differencing operator (where is the backshift operator, ) with a real, non-integer . Expanding by the binomial series,
with weights that follow a simple recursion:
For the weights are (the original series, all memory). For they are (ordinary differencing, returns, no memory). For fractional , the weights decay slowly and never quite vanish, so the transformed series retains long memory while becoming stationary. The recipe:
i.e. sweep upward and pick the smallest at which an Augmented Dickey–Fuller test rejects a unit root. Empirically, many price series become stationary at –, far below the that returns impose, meaning ordinary returns discard memory that a fractionally-differenced feature keeps while remaining perfectly stationary. In practice you truncate the weight window once falls below a threshold.
Detecting structural breaks
Stationarity can fail episodically: the process is stable for a while, then a regime shifts, a policy change, a liquidity crisis, a market-structure reform. Features and relationships that held before the break mislead after it. Tools to flag breaks:
- CUSUM filters on the cumulative sum of standardized returns, which trigger when the running sum breaches a threshold, marking a change in mean.
- Chow / supremum tests for a break at an unknown date, comparing model fits before and after a candidate split point.
- Explosiveness tests (SADF, supremum ADF) that detect bubbles as periods where the series turns locally non-stationary in an explosive direction.
Breaks matter for feature engineering because they define where the past stops being representative, closely related to Regime Detection and to why Cross-Validation for Time Series cannot assume a single stationary distribution.
Worked example
You want a "value" feature from a price series to feed a classifier. Option A: use log returns (). They are stationary and pass ADF instantly, but their autocorrelation is near zero, the classifier sees pure noise. Option B: fractionally difference the log-price. Sweeping , suppose the ADF test first rejects the unit root at . The resulting series is stationary (safe for learning) yet its correlation with the original log-price is still ~0.9, it has kept the level information a return would have destroyed. A tree ensemble trained on the feature can exploit slow mean-reversion that is simply invisible in returns. The difference between a useless feature and a useful one was the choice of differencing order.
Failure modes
- Over-differencing to by reflex, deleting the memory you needed.
- Look-ahead in transforms: computing , ADF thresholds, scalers, or standardization statistics on the full sample leaks the future, fit them inside the training fold. See Look-Ahead Bias.
- Ignoring non-stationarity entirely, feeding raw prices to a model that then fails the moment the level leaves its training range.
- Stale features across a structural break, where a pre-break relationship no longer holds.
- Redundant, collinear features that confound tree-based importance measures, see Tree Ensembles in Finance.
In interviews
A common prompt: "Why not just use returns as your features?", because first-differencing achieves stationarity at the cost of essentially all memory, and predictive structure often lives in the memory. Be ready to explain the stationarity–memory tradeoff, to describe fractional differentiation as choosing the minimum that yields stationarity (preserving maximum memory), and to state the weight recursion . A strong candidate adds that every fitted transform must be estimated inside the training window to avoid look-ahead, and that structural breaks bound how far back the data remains representative. See Triple-Barrier Labeling for the labeling side of the pipeline.
Related concepts
Practice in interviews
Further reading
- López de Prado, Advances in Financial Machine Learning (Ch. 4–5, 17)
- Hosking, Fractional Differencing
- Bailey & López de Prado, Structural Breaks and the Chow Test in Finance