Skip to main content

clean_signals_1d_nb

clean_signals_1d_nb(
    long_entries: numpy.ndarray,
    long_exits: numpy.ndarray,
    short_entries: numpy.ndarray,
    short_exits: numpy.ndarray,
) ‑> Tuple[numpy.ndarray, ...]
Cleans 1d entry and exit signals by ensuring that positions are entered and exited in a logical manner. The function prevents overlapping or redundant signals, ensuring that a position is opened only when there is no existing position and closed only when an open position exists. Parameters:
NameTypeDefaultDescription
long_entriestp.Array1d--Boolean array indicating long entry signals.
long_exitstp.Array1d--Boolean array indicating long exit signals.
short_entriestp.Array1d--Boolean array indicating short entry signals.
short_exitstp.Array1d--Boolean array indicating short exit signals.
Returns:
TypeDescription
tuple of tp.Array1dTuple containing cleaned boolean arrays for long entries, long exits, short entries, and short exits.

clean_signals_nb

clean_signals_nb(
    long_entries: numpy.ndarray,
    long_exits: numpy.ndarray,
    short_entries: numpy.ndarray,
    short_exits: numpy.ndarray,
) ‑> Tuple[numpy.ndarray, ...]
Cleans 2d entry and exit signals by ensuring that positions are entered and exited in a logical manner for each column (asset/time series). The function prevents overlapping or redundant signals for each column, ensuring that a position is opened only when there is no existing position and closed only when an open position exists. Parameters:
NameTypeDefaultDescription
long_entriestp.Array2d--Boolean array indicating long entry signals (time, assets).
long_exitstp.Array2d--Boolean array indicating long exit signals (time, assets).
short_entriestp.Array2d--Boolean array indicating short entry signals (time, assets).
short_exitstp.Array2d--Boolean array indicating short exit signals (time, assets).
Returns:
TypeDescription
tuple of tp.Array2dTuple containing cleaned boolean arrays for long entries, long exits, short entries, and short exits, all in the same shape as input.

fshift_1d_nb

fshift_1d_nb(
    long_entries: numpy.ndarray,
    long_exits: numpy.ndarray,
    short_entries: numpy.ndarray,
    short_exits: numpy.ndarray,
    n: int = 1,
) ‑> Tuple[numpy.ndarray, ...]
Shift forward 1d signal arrays by n positions. Numba equivalent to pd.Series(arr).shift(n). Parameters:
NameTypeDefaultDescription
long_entriestp.Array1d--Boolean array indicating long entry signals.
long_exitstp.Array1d--Boolean array indicating long exit signals.
short_entriestp.Array1d--Boolean array indicating short entry signals.
short_exitstp.Array1d--Boolean array indicating short exit signals.
nint1Number of steps. Defaults to 1.
Returns:
TypeDescription
Signalsshifted signals.

fshift_nb

fshift_nb(
    long_entries: numpy.ndarray,
    long_exits: numpy.ndarray,
    short_entries: numpy.ndarray,
    short_exits: numpy.ndarray,
    n: int = 1,
) ‑> Tuple[numpy.ndarray, ...]
Shift forward 2d signal arrays by n positions. Numba equivalent to pd.Series(arr).shift(n). Parameters:
NameTypeDefaultDescription
long_entriestp.Array1d--Boolean array indicating long entry signals.
long_exitstp.Array1d--Boolean array indicating long exit signals.
short_entriestp.Array1d--Boolean array indicating short entry signals.
short_exitstp.Array1d--Boolean array indicating short exit signals.
nint1Number of steps. Defaults to 1.
Returns:
TypeDescription
Signalsshifted signals.

prepare_signals_nb

prepare_signals_nb(
    signal_func: Callable,
) ‑> Callable
Wraps a signal function to automatically create threshold arrays for predictions. The wrapper ensures that input arrays match the shape of the model_output array and converts them to floating-point type for further processing. Parameters:
NameTypeDefaultDescription
signal_functp.Callable--Function that processes signals using predefined thresholds.
Returns:
TypeDescription
tp.CallableA Numba JIT-compiled function that applies the given signal function with correctly shaped and typed input arrays.