emstd

Defined in fynance.features.momentums

emstd(X, alpha=0.94, w=None, axis=0, dtype=None)[source]

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

\[emstd^{\alpha}_t(X) = \sqrt{\alpha\times emstd^{\alpha}_{t-1}^2 + (1-\alpha) \times X_t^2}\]
Parameters:
Xnp.ndarray[dtype, ndim=1 or 2]

Elements to compute the moving standard deviation.

alphafloat, optional

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

wint, 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.

dtypenp.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]

Exponential moving standard deviation of each series.

See also

ema, smstd, wmstd

Notes

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

Examples

>>> X = np.array([60, 100, 80, 120, 160, 80])
>>> emstd(X, w=3, dtype=np.float64)
array([ 0.        , 14.14213562, 10.        , 15.8113883 , 23.97915762,
       24.49489743])
>>> emstd(X.reshape([6, 1]), w=3, dtype=np.float64).flatten()
array([ 0.        , 14.14213562, 10.        , 15.8113883 , 23.97915762,
       24.49489743])
>>> emstd(X, alpha=0.5, dtype=np.float64)
array([ 0.        , 14.14213562, 10.        , 15.8113883 , 23.97915762,
       24.49489743])