Meta-labelling: a toy example to build intuition
Meta-labelling separates two questions that a trading model usually answers at once: which direction to bet, and whether to bet at all. A primary model, which can be a simple rule, decides the side. A secondary machine-learning model then learns when the primary model tends to be right, and filters or sizes its signals accordingly. A small, deliberately artificial example is the easiest way to see how it works.
All numbers below are hypothetical, chosen to illustrate the arithmetic. They are not results from any dataset or strategy.
Where the idea comes from
Meta-labelling was described by Marcos López de Prado in chapter 3 of Advances in Financial Machine Learning (2018). It builds on the triple-barrier labelling method explained in our laboratory for machine learning in finance. Since then it has been developed further in the academic literature, including a 2022 series of papers in The Journal of Financial Data Science that set out a theoretical framework and model architectures for it.
Step 1: a primary model
Imagine a primary model that is a simple trend rule: go long when a short moving average crosses above a long one, go short when it crosses below. Over a test period it produces 200 signals. With the benefit of hindsight, and using triple-barrier labels to decide whether each signal would have reached its profit target before its stop-loss, suppose 80 signals were good and 120 were bad.
The primary model's precision, the share of its signals that were good, is 80 / 200 = 40 per cent. Because it fires on every crossover, it catches every opportunity it is capable of seeing, so its recall relative to its own opportunities is 100 per cent. This is a typical profile for a simple rule: it misses little, but it is wrong more often than right.
Step 2: build the meta-labels
For each of the 200 primary signals, create a binary meta-label: 1 if the signal turned out good, 0 if bad. The side is already decided by the primary model, so the secondary model never predicts direction. Its only task is to predict the probability that a given signal will be good.
The secondary model's features can include anything known at the time of the signal: recent volatility, the strength of the crossover, the trend of a broader index, volume, the time since the last signal, or the primary model's own recent hit rate. Features must use only information available before the signal, or the exercise is meaningless.
Step 3: train the secondary model
A classifier such as a random forest or logistic regression is trained on the features and meta-labels, using purged cross-validation to avoid leakage between overlapping trades. Its output for each new signal is a probability between 0 and 1. A threshold, for example 0.5, converts that probability into a decision: act on the signal or skip it.
Step 4: count the results
Suppose that on held-out data, the secondary model accepts 90 signals and rejects 110. Among the 90 accepted, 54 were good; among the 110 rejected, 26 were good.
| Good signal | Bad signal | Total | |
|---|---|---|---|
| Accepted (act) | 54 | 36 | 90 |
| Rejected (skip) | 26 | 84 | 110 |
| Total | 80 | 120 | 200 |
The combined system's precision is now 54 / 90 = 60 per cent, up from 40 per cent. Its recall is 54 / 80 = 67.5 per cent: it has given up a third of the good signals to avoid most of the bad ones. The F1 score, the harmonic mean of precision and recall, summarises the balance:
For the primary model alone, F1 = 2 × 0.40 × 1.00 / 1.40 ≈ 0.57. For the combined system, F1 = 2 × 0.60 × 0.675 / 1.275 ≈ 0.64. In this toy case, the filter improves F1. Whether it improves profits depends on the payoffs of good and bad trades and on costs, which the confusion matrix does not show.
Step 5: use probabilities for sizing
A binary filter throws away information. The secondary model's probability can instead be mapped to a position size: small positions when the model is barely confident, larger positions when it is confident. López de Prado discusses bet-sizing functions that convert predicted probabilities into sizes, adjusting for the number of concurrent bets. Sizing by confidence can improve risk-adjusted returns even if the filter alone does not change the hit rate much.
Why separate side and size?
- Interpretability. The primary model can be an economically motivated rule or a discretionary view; the machine-learning layer only judges when to trust it.
- Reduced overfitting of the side. The secondary model cannot invent directional bets from noise.
- Focus on precision. Many simple strategies have high recall and low precision; meta-labelling is designed to raise precision at an acceptable cost in recall.
Limits of the toy
A tidy confusion matrix hides real difficulties. With few signals, the secondary model has little data to learn from, and its apparent improvement may be noise. Features may simply proxy for volatility, so the model ends up as a volatility filter that could be built more simply. And the threshold is itself a parameter that can be overfitted. Our follow-up article, does meta-labelling add to signal efficacy?, discusses how to test the method honestly.
Reproducing the toy yourself
The example can be rebuilt with synthetic data in a few dozen lines of Python: simulate a price series with alternating trending and choppy regimes, apply a crossover rule to generate signals, label each signal with triple barriers, and add a feature that indicates the regime with noise. A classifier trained on that feature should learn to accept signals in trending regimes and reject them in choppy ones. Because the data are synthetic and the regime is known, you can check whether the model learned the right thing, a useful exercise before trying the method on real markets.
Sources
- López de Prado, M. (2018). Advances in Financial Machine Learning. Wiley. Chapter 3 (labelling and meta-labelling) and chapter 10 (bet sizing).
- Joubert, J. F. (2022). Meta-Labeling: Theory and Framework. The Journal of Financial Data Science, 4(3).
- scikit-learn documentation, Precision, recall and F-measures.