finmlkit.feature.core.ma module¶
- finmlkit.feature.core.ma.ewma(y: ndarray[tuple[int, ...], dtype[_ScalarType_co]], span: int) ndarray[tuple[int, ...], dtype[float64]][source]¶
Exponentially weighted moving average (EWMA) of a one-dimensional numpy array. Calculates the equivalent of pandas.DataFrame.ewm(…).mean() with adjust=True.
By using this weighting scheme, the function provides a more accurate and unbiased estimate of the EWMA, especially in the early stages of the data series.
- Parameters:
y – A one-dimensional numpy array of floats.
span – The decay window, or ‘span’. Determines how many past points meaningfully impact the EWMA value.
- Returns:
The EWMA vector, same length and shape as y.
- Raises:
ValueError – If span is less than 1.
Note
This function adjusts for small sample sizes by dividing by the cumulative weight. For more information, see: https://terbe.dev/blog/posts/exponentially-weighted-moving-average
- finmlkit.feature.core.ma.sma(array: ndarray[tuple[int, ...], dtype[float64]], window: int) ndarray[tuple[int, ...], dtype[float64]][source]¶
Calculate Simple Moving Average (SMA) with Numba for better performance.
- Parameters:
array – np.array, input array to calculate SMA
window – int, window for the rolling average
- Returns:
np.array, SMA values