Quant Analytics: from scratch to pro · Machine learning in finance · Advanced
Machine learning as a filter: meta-labelling
Instead of asking a model to find trades, ask it which trades from an existing rule to take. Meta-labelling raises expectancy per trade by skipping likely losers, but it also cuts the trade count, and the gain must survive out-of-sample testing and costs.
In this lesson
- Explain meta-labelling: a primary rule sets the side, a model decides whether to act
- Read a confusion matrix and compute precision, recall and accuracy
- Compute expectancy per trade and in total before and after a filter
- Show why in-sample filter results overstate the benefit
Read first: Features and labels: fixed horizons and the triple barrier, Machine learning for market data: what it can and cannot do
The previous lessons argued that finding trades with a model is hard and that results are easily inflated. There is a more modest and more defensible use: take a rule that already works for an understood reason, and let a model help decide which of its signals to take.
Meta-labelling
In meta-labelling (López de Prado, 2018) two decisions are separated. A primary rule chooses the side of the trade (long or short) and generates the signals. A secondary model receives the features at the time of the signal and predicts whether this signal will be right. The label for the secondary model is binary: did the trade succeed under the triple-barrier definition? Its output can be used to skip the signal, or to scale the size.
The primary rule can be a simple, explainable one. The model never decides direction, so it cannot invent an edge from nothing. It can only help to avoid the worst of the signals the rule gives. See meta-labelling.
Precision and recall
A filter that accepts or rejects signals makes four kinds of outcome. Accepting a winner is a true positive; accepting a loser a false positive; rejecting a winner a false negative; rejecting a loser a true negative.
- Precision = true positives / accepted: how often an accepted trade wins.
- Recall = true positives / all winners: what share of winners the filter keeps.
- Accuracy = correct decisions / all decisions. It can mislead when classes are unbalanced.
Higher precision means a better win rate on trades taken. Higher recall means fewer good trades lost. The two pull against each other as the acceptance threshold moves.
Worked example
A rule gives 400 signals. It wins 44% of the time, with a win worth 1.5R and a loss costing 1R, where R is the amount risked per trade. Expectancy per trade is 0.44 x 1.5 - 0.56 x 1, which is 0.10R, and 40R over 400 trades. There are 176 winners and 224 losers.
A filter accepts 150 signals. Of these, 90 win and 60 lose. The confusion matrix is 90 true positives, 60 false positives, 86 false negatives and 164 true negatives.
- Precision:
90 / 150, which is 60%. - Recall:
90 / 176, which is 51.1%. - Accuracy:
(90 + 164) / 400, which is 63.5%.
If that precision held, expectancy per trade would be 0.6 x 1.5 - 0.4 x 1, which is 0.50R, and 75R over 150 trades. This is the in-sample picture, and it is too good.
The honest version
On new data, precision is usually lower. Suppose it is 50%. Expectancy per trade is 0.25R, still better than 0.10R, but the total over 150 trades is 37.5R, which is less than the unfiltered 40R. Raising expectancy per trade while taking fewer trades does not guarantee a better total.
Costs change the comparison. At 0.05R per trade the unfiltered rule nets 400 x (0.10 - 0.05), which is 20R. The filtered rule at 50% precision nets 150 x (0.25 - 0.05), which is 30R. Fewer trades means fewer costs, and that is where much of a real filter's benefit comes from. Always compare after costs and out of sample, with purged validation (see leakage and purged cross-validation).
Common mistakes
- Reporting precision from the data used to fit the model.
- Looking at expectancy per trade and ignoring the number of trades.
- Optimising the acceptance threshold on the test data.
- Filtering a rule that has no edge. A filter cannot repair one; it makes noise look selective.
- Judging by accuracy when winners and losers are unequal in number or size.
- Forgetting that the filter itself can drift; see calibration and drift monitoring.
In practice
Begin with a rule that works without the model. Build the filter on training folds only, set the threshold in the training data, and report precision, recall, trade count and expectancy with and without the filter, after costs. Keep a check on live precision, because a filter that stops working turns into a source of missed trades.
Worked numbers
Each result is recomputed from the formula shown.
| What | Formula | Result |
|---|---|---|
| winners of the unfiltered rule | 400 * 0.44 | 176 |
| losers of the unfiltered rule | 400 - wins_all | 224 |
| expectancy before the filter, in R | 0.44 * 1.5 - 0.56 * 1 | 0.10R |
| total R before the filter | 400 * exp_before | 40R |
| true positives | 90 | 90 |
| false positives | 60 | 60 |
| false negatives | wins_all - tp | 86 |
| true negatives | losses_all - fp | 164 |
| precision | tp / (tp + fp) | 60% |
| recall | tp / (tp + fn) | 51.1% |
| accuracy | (tp + tn) / 400 | 63.5% |
| expectancy after the filter, in sample | precision * 1.5 - (1 - precision) * 1 | 0.50R |
| total R after the filter, in sample | 150 * exp_in | 75R |
| expectancy with precision 50% | 0.5 * 1.5 - 0.5 * 1 | 0.25R |
| total R with precision 50% | 150 * exp_out | 37.5R |
| total R before the filter after 0.05R costs | 400 * (exp_before - 0.05) | 20R |
| total R after the filter at 50% precision, after costs | 150 * (exp_out - 0.05) | 30R |
Check yourself
A rule has a win rate of 44%, wins 1.5R and loses 1R. What is its expectancy per trade?
0.44 x 1.5 - 0.56 x 1 = 0.66 - 0.56 = 0.10R.
A filter takes 150 trades, 90 of which win. What are the precision and the win rate among taken trades?
Precision = 90 / 150 = 60%, which is also the win rate of the taken trades.
The rule produced 176 winners in all. What is the recall of the filter?
90 / 176 = 51.1%. The filter keeps about half of the winners, and discards the rest along with the losers it skips.
Precision is 60% in training but 50% on new data. What happens to expectancy and to total R?
Expectancy per trade falls from 0.50R to 0.25R. Over 150 trades the total falls from 75R to 37.5R, below the 40R the unfiltered rule earned over 400 trades before costs.
Why does a cost of 0.05R per trade favour the filter?
Costs are paid per trade. The filter takes 150 trades instead of 400, so it pays 7.5R in costs instead of 20R.
Key terms
Sources
- Advances in Financial Machine Learning. Wiley (Marcos López de Prado), 2018. Accessed 9 Nov 2026
- The Elements of Statistical Learning (2nd edition). Springer (Trevor Hastie, Robert Tibshirani, Jerome Friedman), 2009. Accessed 9 Nov 2026