Skip to main content

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.

4 min read Reviewed Revision 1

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

Worked numbers

Each result is recomputed from the formula shown.

WhatFormulaResult
winners of the unfiltered rule400 * 0.44176
losers of the unfiltered rule400 - wins_all224
expectancy before the filter, in R0.44 * 1.5 - 0.56 * 10.10R
total R before the filter400 * exp_before40R
true positives9090
false positives6060
false negativeswins_all - tp86
true negativeslosses_all - fp164
precisiontp / (tp + fp)60%
recalltp / (tp + fn)51.1%
accuracy(tp + tn) / 40063.5%
expectancy after the filter, in sampleprecision * 1.5 - (1 - precision) * 10.50R
total R after the filter, in sample150 * exp_in75R
expectancy with precision 50%0.5 * 1.5 - 0.5 * 10.25R
total R with precision 50%150 * exp_out37.5R
total R before the filter after 0.05R costs400 * (exp_before - 0.05)20R
total R after the filter at 50% precision, after costs150 * (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

Meta-labellingTriple-barrier methodExpectancyWin rate

Sources

Informational content. Not investment advice.