Triple-Barrier Labelling for Financial Machine Learning
A path-dependent labelling method using profit-taking, stop-loss and time barriers, with a compact pandas implementation.
Published 2026-10-11 · Educational explainer, not investment advice
Why fixed-horizon labels fall short
Labelling the sign of the return over a fixed horizon ignores the path. A position that hits its stop-loss before recovering would be labelled a winner, which no real risk process would allow.
The three barriers
Each event gets an upper barrier (profit target), a lower barrier (stop-loss) and a vertical barrier (maximum holding time). The label is set by whichever barrier is touched first. Barrier widths are usually scaled by recent volatility so labels adapt to regime.
def triple_barrier(close, events, pt=1.0, sl=1.0, vol=None, max_h="5D"): out = {} for t0 in events: t1 = t0 + pd.Timedelta(max_h) path = close[t0:t1] / close[t0] - 1 up, dn = pt * vol[t0], -sl * vol[t0] hit_up = path[path >= up].index.min() hit_dn = path[path <= dn].index.min() first = min([x for x in (hit_up, hit_dn, t1) if pd.notna(x)]) out[t0] = 1 if first == hit_up else -1 if first == hit_dn else 0 return pd.Series(out)Meta-labelling
Triple-barrier labels pair naturally with meta-labelling: a primary model proposes the side, and a secondary model learns whether to act on it and how large to size the position.
Source: López de Prado, M. (2018). Advances in Financial Machine Learning. Wiley. Chapter 3.
Run this method as part of a structured research workflow.
Open Voltacent Agent