label_concurrency

Defined in fynance.features.labels

label_concurrency(t_in, t_out, T)[source]

Number of labels alive at each bar (inclusive [t_in, t_out] spans).

Warning

This describes labels, not a feature — see the module warning.

Used by uniqueness_weights, and useful on its own to diagnose how much triple_barrier labels overlap.

Parameters:
t_in, t_outnp.ndarray[int, ndim=1]

Label start / end indices (the t_in / t_out fields of a triple_barrier output), same length, with 0 <= t_in <= t_out <= T - 1 element-wise.

Tint

Number of bars in the underlying series.

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

Shape (T,), the count of labels whose [t_in, t_out] span includes each bar.

Raises:
ValueError

If t_in and t_out have different lengths, or any span falls outside [0, T - 1] or has t_in > t_out.

See also

uniqueness_weights, triple_barrier

References

[1]

Lopez de Prado, M. (2018). Advances in Financial Machine Learning. Wiley. Chapter 4, “Sample Weights”.

Examples

>>> import numpy as np
>>> label_concurrency(np.array([0, 0, 2]), np.array([1, 1, 3]), T=4)
array([2, 2, 1, 1])