fynance.features.metrics.roll_mad¶
-
fynance.features.metrics.
roll_mad
(X, w=None, axis=0, dtype=None)¶ Compute rolling Mean Absolut Deviation for each X’ series.
Compute the moving average of the absolute value of the distance to the moving average [6].
Parameters: - X : np.ndarray[dtype, ndim=1 or 2]
Time series (price, performance or index).
- w : int, optional
Size of the lagged window of the rolling function, 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]
Series of mean absolute deviation.
See also
References
[6] https://en.wikipedia.org/wiki/Average_absolute_deviation Examples
>>> X = np.array([70, 100, 90, 110, 150, 80]) >>> roll_mad(X, dtype=np.float64) array([ 0. , 15. , 11.11111111, 12.5 , 20.8 , 20. ]) >>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64) >>> roll_mad(X, w=3, dtype=np.float64) array([ 0. , 20. , 13.33333333, 13.33333333, 26.66666667, 26.66666667])