roll_z_score¶
Defined in fynance.features.metrics
- roll_z_score(X, w=None, kind='s', axis=0, dtype=None)[source]
Compute vector of rolling/moving Z-score function.
- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Series of index, prices or returns.
- wint, optional
Size of the lagged window of the moving averages, must be positive. If
w is Noneorw=0, thenw=X.shape[axis]. Default is None.- kind{‘e’, ‘s’, ‘w’}
If ‘e’ then use exponential moving average, see
emafor details.If ‘s’ (default) then use simple moving average, see
smafor details.If ‘w’ then use weighted moving average, see
wmafor details.
- 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]
Vector of Z-score at each period.
See also
z_score,roll_mdd,roll_calmar,roll_mad,roll_sharpe
Notes
Compute for each observation the z-score function for a specific moving average function such that \(\forall t \in [1:T]\):
\[z_t = \frac{X_t - \mu_t}{\sigma_t}\]Where \(\mu_t\) is the moving average and \(\sigma_t\) is the moving standard deviation.
Examples
>>> X = np.array([70, 100, 80, 120, 160, 80]).astype(np.float64) >>> roll_z_score(X, w=3, kind='e') array([ 0. , 1.41421356, -0.32444284, 1.30806216, 1.27096675, -1.04435741]) >>> roll_z_score(X, w=3) array([ 0. , 1. , -0.26726124, 1.22474487, 1.22474487, -1.22474487])