Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
nb module

Numba-compiled functions for label generation.

Note

Set `wait` to 1 to exclude the current value from calculation of future values.

Warning

Do not attempt to use these functions for building predictor variables as they may introduce the look-ahead bias to your model - only use for building target variables.

## bin_trend_labels_1d_nb function

    bin_trend_labels_1d_nb(
        pivots
    )

Values classified into 0 (downtrend) and 1 (uptrend).

## bin_trend_labels_nb function

    bin_trend_labels_nb(
        pivots
    )

2-dim version of bin_trend_labels_1d_nb().

## binc_trend_labels_1d_nb function

    binc_trend_labels_1d_nb(
        high,
        low,
        pivots
    )

Median values normalized between 0 (downtrend) and 1 (uptrend).

## binc_trend_labels_nb function

    binc_trend_labels_nb(
        high,
        low,
        pivots
    )

2-dim version of binc_trend_labels_1d_nb().

## bincs_trend_labels_1d_nb function

    bincs_trend_labels_1d_nb(
        high,
        low,
        pivots,
        up_th,
        down_th
    )

Median values normalized between 0 (downtrend) and 1 (uptrend) but capped once the threshold defined at the beginning of the trend is exceeded.

## bincs_trend_labels_nb function

    bincs_trend_labels_nb(
        high,
        low,
        pivots,
        up_th,
        down_th
    )

2-dim version of bincs_trend_labels_1d_nb().

## breakout_labels_1d_nb function

    breakout_labels_1d_nb(
        high,
        low,
        window=14,
        up_th=inf,
        down_th=inf,
        wait=1
    )

For each value, return 1 if any value in the next period is greater than the positive threshold (in %), -1 if less than the negative threshold, and 0 otherwise.

First hit wins. Continue search if both thresholds were hit at the same time.

## breakout_labels_nb function

    breakout_labels_nb(
        high,
        low,
        window=14,
        up_th=inf,
        down_th=inf,
        wait=1
    )

2-dim version of breakout_labels_1d_nb().

## fixed_labels_1d_nb function

    fixed_labels_1d_nb(
        close,
        n=1
    )

Percentage change of the current value relative to a future value.

## fixed_labels_nb function

    fixed_labels_nb(
        close,
        n=1
    )

2-dim version of fixed_labels_1d_nb().

## future_max_1d_nb function

    future_max_1d_nb(
        close,
        window=14,
        wait=1,
        minp=None
    )

Rolling maximum over future values.

## future_max_nb function

    future_max_nb(
        close,
        window=14,
        wait=1,
        minp=None
    )

2-dim version of future_max_1d_nb().

## future_mean_1d_nb function

    future_mean_1d_nb(
        close,
        window=14,
        wtype=0,
        wait=1,
        minp=None,
        adjust=False
    )

Rolling average over future values.

## future_mean_nb function

    future_mean_nb(
        close,
        window=14,
        wtype=0,
        wait=1,
        minp=None,
        adjust=False
    )

2-dim version of future_mean_1d_nb().

## future_min_1d_nb function

    future_min_1d_nb(
        close,
        window=14,
        wait=1,
        minp=None
    )

Rolling minimum over future values.

## future_min_nb function

    future_min_nb(
        close,
        window=14,
        wait=1,
        minp=None
    )

2-dim version of future_min_1d_nb().

## future_std_1d_nb function

    future_std_1d_nb(
        close,
        window=14,
        wtype=0,
        wait=1,
        minp=None,
        adjust=False,
        ddof=0
    )

Rolling standard deviation over future values.

## future_std_nb function

    future_std_nb(
        close,
        window=14,
        wtype=0,
        wait=1,
        minp=None,
        adjust=False,
        ddof=0
    )

2-dim version of future_std_1d_nb().

## iter_symmetric_down_th_nb function

    iter_symmetric_down_th_nb(
        up_th
    )

Negative upper threshold that is symmetric to a positive one at one iteration.

## iter_symmetric_up_th_nb function

    iter_symmetric_up_th_nb(
        down_th
    )

Positive upper threshold that is symmetric to a negative one at one iteration.

For example, 50% down requires 100% to go up to the initial level.

## mean_labels_1d_nb function

    mean_labels_1d_nb(
        close,
        window=14,
        wtype=0,
        wait=1,
        minp=None,
        adjust=False
    )

Percentage change of the current value relative to the average of a future period.

## mean_labels_nb function

    mean_labels_nb(
        close,
        window=14,
        wtype=0,
        wait=1,
        minp=None,
        adjust=False
    )

2-dim version of mean_labels_1d_nb().

## pct_trend_labels_1d_nb function

    pct_trend_labels_1d_nb(
        high,
        low,
        pivots,
        normalize=False
    )

Percentage change of median values relative to the next pivot.

## pct_trend_labels_nb function

    pct_trend_labels_nb(
        high,
        low,
        pivots,
        normalize=False
    )

2-dim version of pct_trend_labels_1d_nb().

## pivots_1d_nb function

    pivots_1d_nb(
        high,
        low,
        up_th,
        down_th
    )

Pivots denoted by 1 (peak), 0 (no pivot) or -1 (valley).

Two adjacent peak and valley points should exceed the given threshold parameters.

If any threshold is given element-wise, it will be applied per new/updated pivot.

## pivots_nb function

    pivots_nb(
        high,
        low,
        up_th,
        down_th
    )

2-dim version of pivots_1d_nb().

## trend_labels_1d_nb function

    trend_labels_1d_nb(
        high,
        low,
        up_th,
        down_th,
        mode=0
    )

Trend labels based on `TrendLabelMode`.

## trend_labels_nb function

    trend_labels_nb(
        high,
        low,
        up_th,
        down_th,
        mode=0
    )

2-dim version of trend_labels_1d_nb().

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings