var

var(x, w=Window(w=None, r=0))[source]

Rolling variance of series over given window

Parameters
  • x (Series) – series: timeseries

  • w (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 variance

Usage

Provides unbiased estimator of sample variance over a rolling window:

\(R_t = \frac{1}{N-1} \sum_{i=t-w+1}^t (X_i - \overline{X_t})^2\)

where \(N\) is the number of observations in each rolling window, \(w\), and \(\overline{X_t}\) is the mean value over the same window:

\(\overline{X_t} = \frac{\sum_{i=t-w+1}^{t} X_i}{N}\)

If window is not provided, computes variance over the full series

Examples

Generate price series and compute variance of returns over \(22\) observations

>>> prices = generate_series(100)
>>> var(returns(prices), 22)

See also

var() mean() std()