zscores¶
-
zscores
(x, w=Window(w=None, r=0))[source]¶ Rolling z-scores over a given window
- Parameters
x (
Series
) – time series of pricesw (
Union
[Window
,int
]) – Window or int: number of observations and ramp up to use. e.g. Window(22, 10) where 22 is the window size
and 10 the ramp up value. Window size defaults to length of series. :rtype:
Series
:return: timeseries of z-scoresUsage
Calculate standard score of each value in series over given window. Standard deviation and sample mean are computed over the specified rolling window, then element is normalized to provide a rolling z-score:
\(R_t = \frac { X_t - \mu }{ \sigma }\)
Where \(\mu\) and \(\sigma\) are sample mean and standard deviation over the given window
If window is not provided, computes z-score relative to mean and standard deviation over the full series
Examples
Generate price series and compute z-score of returns over \(22\) observations
>>> prices = generate_series(100) >>> zscores(returns(prices), 22)
See also