fynance.features.metrics.z_score¶
-
fynance.features.metrics.
z_score
(X, w=0, kind='s', axis=0, dtype=None)¶ Compute the Z-score of each X’ series.
Parameters: - X : np.ndarray[dtype, ndim=1 or 2]
Series of index, prices or returns.
- w : int, optional
Size of the lagged window of the moving averages, must be positive. If
w is None
orw=0
, thenw=X.shape[axis]
. Default is None.- kind : {‘e’, ‘s’, ‘w’}
- 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: - dtype or np.ndarray[dtype, ndim=1]
Value of Z-score for each series.
See also
Notes
Compute the z-score function for a specific average and standard deviation function such that:
\[z = \frac{X_t - \mu_t}{\sigma_t}\]Where \(\mu_t\) is the average and \(\sigma_t\) is the standard deviation.
Examples
>>> X = np.array([70, 100, 80, 120, 160, 80]).astype(np.float64) >>> z_score(X, w=3, kind='e') -1.0443574118998766 >>> z_score(X, w=3) -1.224744871391589 >>> z_score(X.reshape([6, 1]), w=3) array([-1.22474487])