Numba Tools Module¶
Numba-accelerated kernels for technical indicator calculations (EMA, SMA, RMA, RSI).
Functions:
|
Calculate the rolling maximum and the number of steps back to the rolling maximum within a moving window. |
Calculate the rolling maximum and the steps back to the maximum for the last value in the input array. |
|
|
Calculate the rolling minimum and the number of steps back to the rolling minimum within a moving window. |
Calculate the rolling minimum for the last value in the given array using NumPy. |
|
|
Calculate the Exponential Moving Average (EMA) of the given array. |
|
Calculate the Rolling Moving Average (RMA) of the given array. |
|
Calculate the Relative Strength Index (RSI) for an array of closing prices. |
|
Calculate the Simple Moving Average (SMA) of the given array using NumPy. |
|
Calculate the logarithmic ratio between the closing price and the closest support level. |
|
Calculate the logarithmic ratio between the closing price and the closest support level for each point in time, where the support levels can change over time. |
|
Calculate the logarithmic ratio between a single closing price and the closest support level to it. |
|
Calculate the logarithmic ratio between the closest resistance level and the closing price. |
|
Calculate the logarithmic ratio between the closest resistance level and the closing price for each point in time, where the resistance levels can change over time. |
|
Calculate the logarithmic ratio between the closest resistance level and a single closing price. |
|
Calcula las relaciones de media móvil exponencial (EMA) para una serie de valores, utilizando un conjunto de ventanas especificadas. |
- rolling_max_with_steps_back_numba(values, window, pct_diff) tuple[ndarray, ndarray][source]¶
Calculate the rolling maximum and the number of steps back to the rolling maximum within a moving window.
- Parameters:
values – A 1D NumPy array containing the input data.
window – An integer specifying the size of the moving window.
pct_diff – A boolean to determine if the output should be the percentage difference between the current value and the rolling maximum. If False, the rolling maximum is returned.
- Returns:
A tuple of two 1D NumPy arrays. The first array is the rolling maximum or the percentage difference (based on pct_diff). The second array contains the number of steps back to the rolling maximum.
- rolling_max_with_steps_back_last_value_numba(values: ndarray, window: int, pct_diff: bool) tuple[float, int][source]¶
Calculate the rolling maximum and the steps back to the maximum for the last value in the input array.
- Parameters:
values – A 1D NumPy array containing the input data.
window – An integer specifying the size of the moving window.
pct_diff – A boolean to determine if the output should be the percentage difference between the last value and its rolling maximum. If False, the rolling maximum is returned.
- Returns:
A tuple containing the rolling maximum or the percentage difference (based on pct_diff) for the last value, and the steps back to the rolling maximum for the last value.
- rolling_min_with_steps_back_numba(values, window, pct_diff) tuple[ndarray, ndarray][source]¶
Calculate the rolling minimum and the number of steps back to the rolling minimum within a moving window.
- Parameters:
values – A 1D NumPy array containing the input data.
window – An integer specifying the size of the moving window.
pct_diff – A boolean to determine if the output should be the percentage difference between the current value and the rolling minimum. If False, the rolling minimum is returned.
- Returns:
A tuple of two 1D NumPy arrays. The first array is the rolling minimum or the percentage difference (based on pct_diff). The second array contains the number of steps back to the rolling minimum.
- rolling_min_with_steps_back_last_value_numba(values: ndarray, window: int, pct_diff: bool) tuple[float, int][source]¶
Calculate the rolling minimum for the last value in the given array using NumPy.
- Parameters:
values – A NumPy array containing the input data.
window – An integer for the window size.
pct_diff – A boolean indicating whether to calculate the percentage difference.
- Returns:
A tuple containing the rolling minimum value and the steps back for the last value.
- ema_numba(arr: ndarray, window: int) ndarray[source]¶
Calculate the Exponential Moving Average (EMA) of the given array.
- Parameters:
arr – A 1D NumPy array containing the input data.
window – An integer specifying the size of the moving window for EMA calculation.
- Returns:
A 1D NumPy array containing the EMA values.
Note: The EMA is calculated using the formula EMA[today] = (Value[today] * (2 / (1 + window))) + (EMA[yesterday] * (1 - (2 / (1 + window)))).
- rma_numba(values: ndarray, window: int) ndarray[source]¶
Calculate the Rolling Moving Average (RMA) of the given array.
- Parameters:
values – A 1D NumPy array containing the input data.
window – An integer specifying the size of the moving window for RMA calculation.
- Returns:
A 1D NumPy array containing the RMA values.
Note: The RMA is a type of moving average that gives more weight to recent data points, similar to the EMA.
- rsi_numba(close: ndarray, window: int) ndarray[source]¶
Calculate the Relative Strength Index (RSI) for an array of closing prices.
- Parameters:
close – A 1D NumPy array containing the closing prices.
window – An integer specifying the size of the moving window for RSI calculation.
- Returns:
A 1D NumPy array containing the RSI values.
Note: The RSI is calculated using the formula RSI = 100 - (100 / (1 + (Average Gain / Average Loss))).
- sma_numba(arr: ndarray, window: int) ndarray[source]¶
Calculate the Simple Moving Average (SMA) of the given array using NumPy.
- Args:
arr: A NumPy array containing the input data. window: The window size for the SMA calculation.
- Returns:
A NumPy array containing the SMA values.
Example:
import numpy as np arr = np.array([1.0, 2.5, 3.7, 4.2, 5.0, 6.3]) window = 3 sma_result = sma_numpy(arr, window) print(sma_result) [ nan nan 2.4 3.46666667 4.3 5.16666667]
- close_support_log_numba(close: ndarray, support: ndarray) ndarray[source]¶
Calculate the logarithmic ratio between the closing price and the closest support level.
- Parameters:
close – A NumPy array containing the closing prices.
support – A NumPy array containing the support levels.
- Returns:
A NumPy array containing the logarithmic ratio.
- close_support_dynamic_numba(close: ndarray, supports: ndarray) ndarray[source]¶
Calculate the logarithmic ratio between the closing price and the closest support level for each point in time, where the support levels can change over time.
- Parameters:
close – A NumPy array containing the closing prices.
supports – A 2D NumPy array where each row contains the support levels at a given time.
- Returns:
A NumPy array containing the logarithmic ratio for each point in time.
- close_support_log_single_numba(close: ndarray, support: ndarray) float64[source]¶
Calculate the logarithmic ratio between a single closing price and the closest support level to it.
- Parameters:
close – A single closing price (float).
support – A NumPy array containing the support levels.
- Returns:
The logarithmic ratio for the given closing price.
- close_resistance_log_numba(close: ndarray, resistance: ndarray) ndarray[source]¶
Calculate the logarithmic ratio between the closest resistance level and the closing price.
- Parameters:
close – A NumPy array containing the closing prices.
resistance – A NumPy array containing the resistance levels.
- Returns:
A NumPy array containing the logarithmic ratio.
- close_resistance_dynamic_numba(close: ndarray, resistances: ndarray) ndarray[source]¶
Calculate the logarithmic ratio between the closest resistance level and the closing price for each point in time, where the resistance levels can change over time.
- Parameters:
close – A NumPy array containing the closing prices.
resistances – A 2D NumPy array where each row contains the resistance levels at a given time.
- Returns:
A NumPy array containing the logarithmic ratio for each point in time.
- close_resistance_log_single_numba(close: ndarray, resistance: ndarray) float64[source]¶
Calculate the logarithmic ratio between the closest resistance level and a single closing price.
- Parameters:
close – A single closing price (float).
resistance – A NumPy array containing the resistance levels.
- Returns:
The logarithmic ratio for the given closing price.
- calculate_ema_relations(arr: ndarray, windows: ndarray, epsilon: float = 1e-08) list[ndarray][source]¶
Calcula las relaciones de media móvil exponencial (EMA) para una serie de valores, utilizando un conjunto de ventanas especificadas.
La función utiliza Numba para la optimización del cálculo, especialmente efectiva en grandes conjuntos de datos. Para cada ventana en ‘windows’, calcula la EMA de la serie ‘arr’. Luego, ajusta los valores de EMA para evitar divisiones por cero, usando ‘epsilon’. Finalmente, devuelve una lista de arrays, cada uno representando la serie ‘arr’ dividida por su respectiva EMA calculada.
:param arr : Array de valores para el cálculo de EMA. :param windows : Array de ventanas para el cálculo de EMA. :param epsilon : Valor de ajuste para evitar divisiones por cero. :return : Lista de arrays, cada uno representando la serie ‘arr’ dividida por su respectiva EMA calculada.