Quant Memo
Advanced

Tree Ensembles in Finance

Random forests and gradient boosting on financial data, why their flexibility overfits low-signal, non-stationary markets, and why their feature-importance measures mislead.

Prerequisites: Overfitting, Cross-Validation for Time Series

Random forests and gradient-boosted trees are the default nonlinear models in applied machine learning, and for good reason: they handle mixed feature types, capture interactions automatically, and need little preprocessing. Turned on financial data, however, their greatest strength, flexibility, becomes their greatest danger. Markets have a signal-to-noise ratio close to zero and a non-stationary data-generating process, and a sufficiently flexible learner will happily fit the noise and the vanished regime. Understanding why tree ensembles overfit here, and why their feature-importance outputs lie, separates practitioners from Kaggle-trained newcomers.

How the two ensembles differ

  • Random forests (bagging). Fit many deep trees, each on a bootstrap resample of the data and each split restricted to a random subset of features. Averaging decorrelated trees reduces variance without much bias. The generalization error of a forest is governed by the variance–correlation identity: for TT trees each with variance σ2\sigma^2 and pairwise correlation ρ\rho, the ensemble variance is
Var(fˉ)=ρσ2+1ρTσ2.\operatorname{Var}(\bar f) = \rho\,\sigma^2 + \frac{1-\rho}{T}\,\sigma^2.

As TT\to\infty the second term vanishes but the first, ρσ2\rho\sigma^2, does not, so the whole game is decorrelating the trees, which random feature selection is designed to do.

  • Gradient boosting (XGBoost, LightGBM). Fit trees sequentially, each new tree targeting the residual errors of the running ensemble. Boosting reduces bias aggressively and can drive training error to zero, which makes it especially prone to memorizing noise on low-signal data.

Why they overfit financial data

  • Near-zero signal. If the true predictable component of returns is tiny, a flexible model fits mostly noise. Deep trees can carve the feature space finely enough to "explain" idiosyncratic past moves that never recur.
  • Non-stationarity. Trees assume the training distribution matches the test distribution. When regimes shift, the partitions a tree learned encode a world that no longer exists, see Feature Engineering for Finance on structural breaks.
  • The iid-bootstrap fallacy. Bagging's bootstrap assumes independent observations. Financial observations are serially correlated and, with Triple-Barrier Labeling, have overlapping labels. Redundant, near-duplicate observations get sampled repeatedly, so the bootstrap trees are far more correlated than the algorithm believes, the forest is effectively smaller and more confident than it should be. López de Prado's sequential bootstrap and reduced max_samples mitigate this.
  • Optimistic validation. If tuned with naive cross-validation, hyperparameters are chosen on leaked scores. Only Purged & Embargoed Cross-Validation gives an honest signal for model selection.

The feature-importance traps

Tree ensembles produce feature-importance rankings that look authoritative and are routinely misread.

Mean Decrease Impurity (MDI), the default feature_importances_, sums the impurity reduction each feature contributes across all splits. It is biased:

  • toward high-cardinality / continuous features, which offer more split points and can reduce impurity by chance;
  • toward features examined more often; and
  • it is in-sample, so it rewards features that helped the model overfit.

Mean Decrease Accuracy (MDA / permutation importance) shuffles one feature and measures the drop in out-of-sample score. Better, but on time series it must be run under purged, embargoed CV, or the "out-of-sample" drop is itself leaked.

Substitution effects. When two features are correlated (ubiquitous in finance, value and quality, many momentum lookbacks), the ensemble splits on whichever it happens to pick first, and the other's importance is masked to near zero even though it is equally predictive. Both MDI and permutation importance suffer this. Remedies: cluster correlated features and measure importance per cluster (López de Prado's clustered MDI/MDA), or compute single-feature importance by training one model per feature to sidestep substitution.

Worked example

You train a random forest on 30 features to predict triple-barrier labels and get a cross-validated accuracy of 58% with naive k-fold. Two problems hide inside that number. First, the k-fold split leaked through overlapping labels, under purged, embargoed CV the accuracy falls to ~51%, barely above a coin flip. Second, the MDI importances rank a noisy, high-cardinality feature (say, a raw price level with thousands of distinct values) at the top, purely because it offered the most split points; a genuinely informative but coarse binary feature ranks near the bottom. Acting on the MDI ranking, you would drop the useful feature and keep the artifact. Switching to clustered permutation importance under purged CV reorders the list entirely, and the honest accuracy tells you the model has almost no edge.

Failure modes

  • Trusting MDI, which is in-sample and biased toward continuous, high-cardinality features.
  • Permutation importance without purging, leaking the very information it claims to measure out-of-sample.
  • Substitution masking, where correlated features hide each other's importance, cluster before ranking.
  • Bootstrap over-confidence from overlapping, serially correlated observations, use sequential bootstrap / sample-uniqueness weights.
  • Unpurged hyperparameter tuning, selecting complexity on leaked scores and baking overfitting in.
  • Deep boosting on low-signal data, driving training error to zero and memorizing noise, regularize hard (shallow trees, strong shrinkage, early stopping).

In interviews

A frequent prompt: "Why might a random forest that cross-validates at 58% accuracy fail live?" Name the two culprits, leaked validation from overlapping labels (fix with purged, embargoed CV) and near-zero true signal that the flexible model overfits. Expect a feature-importance follow-up: explain that MDI is in-sample and biased toward high-cardinality features, that permutation (MDA) is better but must be purged, and that correlated features create substitution effects that mask importance, so you cluster features first. The mature takeaway: on non-stationary, low-signal financial data, tree ensembles need heavy regularization, honest (Purged & Embargoed Cross-Validation) validation, and skepticism toward their own importance scores, and even then the results feed straight into the Backtest Overfitting question.

Related concepts

Practice in interviews

Further reading

  • López de Prado, Advances in Financial Machine Learning (Ch. 6, 8)
  • Hastie, Tibshirani & Friedman, The Elements of Statistical Learning (Ch. 10, 15)
  • Strobl et al., Bias in Random Forest Variable Importance Measures
ShareTwitterLinkedIn