volatility

volatility(x, w=Window(w=None, r=0), returns_type=<Returns.SIMPLE: 'simple'>)[source]

Realized volatility of price series

Parameters
  • x (Series) – time series of prices

  • 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. :type returns_type: Returns :param returns_type: returns type :rtype: Series :return: date-based time series of return

Usage

Calculate rolling annualized realized volatility of a price series over a given window. Annual volatility of 20% is returned as 20.0:

\(Y_t = \sqrt{\frac{1}{N-1} \sum_{i=t-w+1}^t (R_t - \overline{R_t})^2} * \sqrt{252} * 100\)

where N is the number of observations in each rolling window, \(w\), \(R_t\) is the simple return on time \(t\):

\(R_t = \frac{X_t}{X_{t-1}} - 1\)

and \(\overline{R_t}\) is the mean value over the same window:

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

If window is not provided, computes realized volatility over the full series

Examples

Compute rolling \(1\) month (\(22\) business day) annualized volatility of price series

>>> series = generate_series(100)
>>> vol_series = volatility(series, 22)
>>> vol_series = volatility(series, Window(22, 30))

See also

std() annualize() returns()