Previous topic

fynance.features.metrics.sharpe

Next topic

fynance.features.metrics.roll_annual_return

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 or w=0, then w=X.shape[axis]. Default is None.

kind : {‘e’, ‘s’, ‘w’}
  • If ‘e’ then use exponential moving average, see ema for details.
  • If ‘s’ (default) then use simple moving average, see sma for details.
  • If ‘w’ then use weighted moving average, see wma for details.
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.

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])