meta_labels

Defined in fynance.features.labels

meta_labels(side, labels)[source]

Meta-label a primary side prediction against realized outcomes.

Warning

This is a label, not a feature — see the module warning.

A meta-label answers “was the primary model’s side call correct?”; it is the target of a secondary model that learns to size (or filter) the primary model’s bets (AFML ch. 3).

Parameters:
sidenp.ndarray[dtype, ndim=1]

Primary model’s predicted direction per event, in {-1, 0, +1} (0 meaning “no bet”), aligned one-to-one with labels.

labelsnp.ndarray[LABEL_DTYPE, ndim=1]

Output of triple_barrier (only the ret field is used).

Returns:
np.ndarray[np.float64, ndim=1]

1.0 where side * ret > 0 (the side call and the realized return agree), 0.0 otherwise — including every side == 0 bet and every ret == 0 (vertical-barrier) outcome.

Raises:
ValueError

If side and labels have different lengths.

See also

triple_barrier

References

[1]

Lopez de Prado, M. (2018). Advances in Financial Machine Learning. Wiley. Chapter 3, “Labeling”.

Examples

>>> import numpy as np
>>> labels = np.array(
...     [(0, 1, 1, 0.05), (0, 2, -1, -0.03), (0, 3, 0, 0.0)],
...     dtype=LABEL_DTYPE,
... )
>>> meta_labels(np.array([1, 1, -1]), labels)
array([1., 0., 0.])