Quant Memo
Advanced

Triple-Barrier Labeling

López de Prado's method for turning price paths into supervised-learning labels, a profit-taking barrier, a stop-loss barrier, and a time barrier, plus meta-labeling to separate the side of a bet from its size.

Prerequisites: Feature Engineering for Finance, Look-Ahead Bias

Before you can train a supervised model on markets you must decide what it is predicting, the label. The naive choice, "the sign of the return over the next hh days," is a poor label: it ignores the path taken to get there, assigns the same label to a smooth ride and a gut-wrenching drawdown that only recovers at the horizon, and takes no account of risk. Triple-barrier labeling is López de Prado's path-aware alternative. It labels each observation by which of three barriers the price touches first, mirroring how a real position with a profit target and a stop-loss actually resolves.

The three barriers

For an event at time t0t_0 with an estimate of local volatility σt0\sigma_{t_0}, set:

  1. Upper (profit-taking) barrier at +πuσt0+\pi_u\,\sigma_{t_0} above entry.
  2. Lower (stop-loss) barrier at πlσt0-\pi_l\,\sigma_{t_0} below entry.
  3. Vertical (time) barrier at t0+ht_0 + h.

The horizontal barriers are dynamic: they scale with the current volatility estimate σt0\sigma_{t_0}, so a 2% move means something different in calm and turbulent markets. The label is determined by the first barrier the path touches:

yt0={+1upper barrier hit first (take profit),1lower barrier hit first (stopped out),    0 or sign(r)vertical barrier hit first (timed out).y_{t_0} = \begin{cases} +1 & \text{upper barrier hit first (take profit)},\\[2pt] -1 & \text{lower barrier hit first (stopped out)},\\[2pt] \;\;0 \text{ or } \operatorname{sign}(r) & \text{vertical barrier hit first (timed out)}. \end{cases}

Formally, with return path rt0tr_{t_0 \to t}, the touch time is τ=min{t:rt0tπuσt0 or rt0tπlσt0 or t=t0+h}\tau = \min\{t : r_{t_0\to t} \ge \pi_u\sigma_{t_0} \text{ or } r_{t_0\to t} \le -\pi_l\sigma_{t_0} \text{ or } t = t_0+h\}, and the label reads off the outcome at τ\tau. The interval [t0,τ][t_0, \tau] is the observation's label span, precisely the object that purging and embargoing operate on in Purged & Embargoed Cross-Validation, because overlapping spans leak information across CV folds.

Why path-awareness matters

A fixed-horizon return label says +3%+3\%-at-day-10 is a win, even if the position was down 15%-15\% on day 3 and would have been stopped out by any real risk manager. Triple-barrier labels resolve at the stop, so they encode the tradeable outcome, not an idealized end-point. Asymmetric multipliers (πuπl\pi_u \neq \pi_l) let you encode a target risk/reward. Scaling barriers by σt0\sigma_{t_0} makes labels comparable across regimes, which is essential once you feed them to a model that assumes roughly stationary targets, see Feature Engineering for Finance.

Meta-labeling

The second idea is to separate the side of a bet from the size. Run a primary model (or a simple rule) that decides the direction, long or short. Then train a secondary, meta-labeling model whose target is binary: given that the primary model took a position, was it correct? The meta-model's label is

mt0=1{primary side=realized triple-barrier sign},m_{t_0} = \mathbb{1}\{\text{primary side} = \text{realized triple-barrier sign}\},

and it predicts Pr(correctfeatures)\Pr(\text{correct} \mid \text{features}). This decomposition is powerful for three reasons:

  • Precision/recall control. The primary model sets recall (it takes many positions, catching most opportunities); the meta-model raises precision by vetoing the low-confidence ones. This tends to improve the F1 score more than trying to build one model that does both.
  • Position sizing. The meta-model's probability output maps naturally to a bet size, trade big when Pr(correct)\Pr(\text{correct}) is high, small or zero when low, a clean bridge to Position Sizing and fractional The Kelly Criterion.
  • Model reuse. You can bolt meta-labeling onto an existing signal (even a discretionary or fundamental one) to learn when to trust it without rebuilding the primary logic.

Worked example

Daily bars, volatility estimate σt0=2%\sigma_{t_0} = 2\%, symmetric multipliers πu=πl=2\pi_u = \pi_l = 2, horizon h=5h = 5 days. The barriers sit at ±4%\pm 4\%. At an event on Monday:

  • Price rises +4.1%+4.1\% by Wednesday → upper barrier touched first → label +1+1, span [Mon,Wed][\text{Mon}, \text{Wed}].
  • Alternatively it falls 4%-4\% by Tuesday → lower barrier → label 1-1, span [Mon,Tue][\text{Mon}, \text{Tue}].
  • Alternatively it drifts to +1%+1\% at Friday's close without touching either → vertical barrier → label 00 (or sign=+1\operatorname{sign}=+1 if you label timeouts by direction), span [Mon,Fri][\text{Mon}, \text{Fri}].

Now the meta-layer: suppose the primary rule went long every Monday. The meta-model learns from features (volatility, momentum, order-flow) to predict whether that long will hit the upper barrier before the lower, and outputs a probability that becomes the position size. Note the label spans differ per observation and overlap neighbors, which is exactly why the classifier must be validated with purging and embargo, not naive k-fold.

Failure modes

  • Overlapping labels ignored. Adjacent observations share label spans; validating with ordinary Cross-Validation for Time Series leaks and inflates accuracy. Purge and embargo.
  • Look-ahead in σt0\sigma_{t_0}. The volatility used to size barriers must be estimated only from data up to t0t_0; a full-sample or centered estimate is Look-Ahead Bias.
  • Class imbalance. Timeouts and one-sided markets skew the label distribution; weight samples by their uniqueness (inverse of how many other labels overlap them) and by return magnitude.
  • Barrier mis-specification. Barriers too tight relative to noise produce near-random labels; too wide and almost everything times out.
  • Ignoring sample weights. Overlapping labels mean observations are not equally informative; López de Prado's average-uniqueness weighting corrects the redundancy.

In interviews

Expect "how would you label financial data for a classifier?" A strong answer rejects the naive fixed-horizon sign, describes the three barriers (profit-take, stop-loss, time) scaled by local volatility, and labels by which is touched first. Follow-ups probe meta-labeling, be ready to explain that the primary model picks the side and the meta-model picks the size by predicting whether the primary was right, improving precision and feeding position sizing. Close by connecting the label span to Purged & Embargoed Cross-Validation: because triple-barrier labels overlap in time, honest validation requires purging and embargoing.

Related concepts

Practice in interviews

Further reading

  • López de Prado, Advances in Financial Machine Learning (Ch. 3)
  • López de Prado, The 10 Reasons Most Machine Learning Funds Fail
  • Prado & Lewis, Detection of False Investment Strategies
ShareTwitterLinkedIn