Trade Filter ML
A leakage-safe meta-labeling study with a pre-registered holdout, asking whether ML can filter a simple trading rule’s signals well enough to matter after costs.
Result: On a pre-registered holdout the filter improved all three strategies, but no gain was statistically distinguishable from zero.
The question
Simple trading rules such as breakouts and moving-average crossovers fire often and, after costs, mostly lose money. Meta-labeling trains a second model that looks at each signal when it fires and decides whether to take it. The question: can such a filter, using only information available at that moment, beat both the unfiltered rule and a random filter that keeps the same share of trades?
It is very easy to fool yourself here. Overlapping trades leak information between training and test folds, repeated tuning overfits the validation data, and a filter that keeps fewer trades can look better by chance alone. The project is built around not falling for any of these.
What I built
- Labels: triple-barrier labels (take-profit, stop-loss and time limit) with sample weights that account for overlapping trades.
- Validation: purged and embargoed cross-validation, with hyperparameters tuned in an inner loop so the outer score is never used for tuning.
- Negative controls: every filter is compared against 2,000 random filters that keep the same share of trades, and against shuffled labels.
- Overfitting statistics: the deflated Sharpe ratio and the probability of backtest overfitting, to account for how many configurations were tried.
- A pre-registered holdout: the code refuses to touch the holdout period (January 2025 to October 2026) until the final configuration is written down and frozen.
- Five development experiments (model family, feature groups, training scope, decision rule, tuning budget) chose that configuration: a LightGBM model, Platt-calibrated, that sizes positions by its confidence.
Result
On the holdout, the frozen filter improved the average trade for all three strategies, including the EMA crossover, which was never used during development. But every 95% interval includes zero, so the pre-registered success criteria were not met. I report it as a null result.
The negative control asks a stricter question: does the model beat filters that throw away the same share of trades at random? It did for the Donchian breakout, narrowly missed the 95% criterion for the EMA crossover, and did not for Bollinger + RSI.
| Strategy | Trades kept | Change in R | 95% low | 95% high | Beats random | AUC |
|---|---|---|---|---|---|---|
| Donchian breakout | 31% | +0.067 | -0.014 | +0.146 | 99.6% | 0.52 |
| Bollinger + RSI fade | 23% | +0.035 | -0.068 | +0.174 | 81.6% | 0.52 |
| EMA crossover (held out) | 52% | +0.042 | -0.031 | +0.142 | 94.8% | 0.50 |
What I learned
In development, a small signal from volatility, trend strength and volume at the moment of the signal beat random filters of the same size. On the holdout it pointed the same way at about half the size and could not be confirmed. Neither the filter nor any setting I tested makes these strategies reliably profitable after costs. Building the guardrails first is what made it possible to say that with confidence instead of publishing an overfit backtest.
Built with
Experiment design and honest validation, Gradient boosting (LightGBM, XGBoost), scikit-learn, Probability calibration, Hyperparameter search with Optuna, Experiment tracking with MLflow, Explainability with SHAP, pandas and NumPy, Market data (yfinance, CCXT, NSE), Performance and risk metrics (Sharpe, drawdown, deflated Sharpe), Python