fynance.features.momentums.wma¶
-
fynance.features.momentums.
wma
(X, w=None, axis=0, dtype=None)¶ Compute weighted moving average(s) of size w for each X’ series.
\[wma^w_t(X) = \frac{2}{w (w-1)} \sum^{w-1}_{i=0} (w-i) \times X_{t-i}\]Parameters: - X : np.ndarray[dtype, ndim=1 or 2]
Elements to compute the moving average.
- w : int, optional
Size of the lagged window of the moving average, must be positive. If
w is None
orw=0
, thenw=X.shape[axis]
. 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.
Returns: - np.ndarray[dtype, ndim=1 or 2]
Weighted moving average of each series.
Examples
>>> X = np.array([60, 100, 80, 120, 160, 80]) >>> wma(X, w=3, dtype=np.float64) array([ 60. , 86.66666667, 83.33333333, 103.33333333, 133.33333333, 113.33333333]) >>> X = X.reshape([6, 1]) >>> wma(X, w=3, dtype=np.float64).flatten() array([ 60. , 86.66666667, 83.33333333, 103.33333333, 133.33333333, 113.33333333])