Skip to content

nb module

Numba-compiled functions.

Provides an arsenal of Numba-compiled functions that are used by indicator classes. These only accept NumPy arrays and other Numba-compatible types.

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 features as they may introduce look-ahead bias to your model.


bn_cont_sat_trend_labels_nb function

bn_cont_sat_trend_labels_nb(
    close,
    local_extrema,
    pos_th,
    neg_th,
    flex_2d=True
)

Similar to bn_cont_trend_labels_nb() but sets each close value to 0 or 1 if the percentage change to the next extremum exceeds the threshold set for this range.


bn_cont_trend_labels_nb function

bn_cont_trend_labels_nb(
    close,
    local_extrema
)

Normalize each range between two extrema between 0 (will go up) and 1 (will go down).


bn_trend_labels_nb function

bn_trend_labels_nb(
    close,
    local_extrema
)

Return 0 for H-L and 1 for L-H.


breakout_labels_nb function

breakout_labels_nb(
    close,
    window,
    pos_th,
    neg_th,
    wait=1,
    flex_2d=True
)

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.


fixed_labels_apply_nb function

fixed_labels_apply_nb(
    close,
    n
)

Get percentage change from the current value to a future value.


future_max_apply_nb function

future_max_apply_nb(
    close,
    window,
    wait=1
)

Get the maximum of the next period.


future_mean_apply_nb function

future_mean_apply_nb(
    close,
    window,
    ewm,
    wait=1,
    adjust=False
)

Get the mean of the next period.


future_min_apply_nb function

future_min_apply_nb(
    close,
    window,
    wait=1
)

Get the minimum of the next period.


future_std_apply_nb function

future_std_apply_nb(
    close,
    window,
    ewm,
    wait=1,
    adjust=False,
    ddof=0
)

Get the standard deviation of the next period.


get_symmetric_neg_th_nb function

get_symmetric_neg_th_nb(
    pos_th
)

Compute the negative return that is symmetric to a positive one.


get_symmetric_pos_th_nb function

get_symmetric_pos_th_nb(
    neg_th
)

Compute the positive return that is symmetric to a negative one.

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


local_extrema_apply_nb function

local_extrema_apply_nb(
    close,
    pos_th,
    neg_th,
    flex_2d=True
)

Get array of local extrema denoted by 1 (peak) or -1 (trough), otherwise 0.

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

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

Inspired by https://www.mdpi.com/1099-4300/22/10/1162/pdf


mean_labels_apply_nb function

mean_labels_apply_nb(
    close,
    window,
    ewm,
    wait=1,
    adjust=False
)

Get the percentage change from the current value to the average of the next period.


pct_trend_labels_nb function

pct_trend_labels_nb(
    close,
    local_extrema,
    normalize
)

Compute the percentage change of the current value to the next extremum.


trend_labels_apply_nb function

trend_labels_apply_nb(
    close,
    pos_th,
    neg_th,
    mode,
    flex_2d=True
)

Apply a trend labeling function based on TrendMode.