fynance.features.momentums.wmstd¶
-
fynance.features.momentums.
wmstd
(X, w=None, axis=0, dtype=None)¶ Compute weighted moving standard(s) deviation for each X’ series’.
\[\begin{split}wma^w_t(X) = \frac{2}{w (w-1)} \sum^{w-1}_{i=0} (w-i) \times X_{t-i} \\ wmstd^w_t(X) = \sqrt{\frac{2}{w(w-1)} \sum^{w-1}_{i=0} (w-i) \times (X_{t-i} - wma^w_t(X))^2}\end{split}\]Parameters: - X : np.ndarray[dtype, ndim=1 or 2]
Elements to compute the moving standard deviation.
- 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 standard deviation of each series.
Examples
>>> X = np.array([60, 100, 80, 120, 160, 80]) >>> wmstd(X, w=3, dtype=np.float64) array([ 0. , 18.85618083, 13.74368542, 17.95054936, 29.8142397 , 35.90109871]) >>> wmstd(X.reshape([6, 1]), w=3, dtype=np.float64).flatten() array([ 0. , 18.85618083, 13.74368542, 17.95054936, 29.8142397 , 35.90109871])