Previous topic


Next topic



fynance.features.momentums.ema(X, alpha=0.94, w=None, axis=0, dtype=None)

Compute exponential moving average(s) for each X’ series.

\[ema^{\apha}_t(X) = \alpha \times ema^{\alpha}_{t-1} + (1-\alpha) \times X_t\]
X : np.ndarray[dtype, ndim=1 or 2]

Elements to compute the moving average.

alpha : float, optional

These coefficient represents the degree of weighting decrease, default is 0.94 corresponding at 20 lags memory.

w : int, optional

Size of the lagged window of the moving average, must be strictly positive. If w is None the window is ignored and the parameter alpha is used. Default is None.

axis : {0, 1}, optional

Axis along wich the computation is done. Default is 0.

dtype : np.dtype, optional

The type of the output array. If dtype is not given, infer the data type from X input.

np.ndarray[dtype, ndim=1 or 2]

Exponential moving average of each series.

See also

sma, wma, emstd


If the lagged window w is specified \(\alpha\) is overwritten by \(\alpha = 1 - \frac{2}{1 + w}\)


>>> X = np.array([60, 100, 80, 120, 160, 80])
>>> ema(X, w=3, dtype=np.float64)
array([ 60.,  80.,  80., 100., 130., 105.])
>>> ema(X, alpha=0.5, dtype=np.float64)
array([ 60.,  80.,  80., 100., 130., 105.])