gs_quant.timeseries.econometrics.volatility

volatility(x, w=<gs_quant.timeseries.helper.Window object>, returns_type=Returns.SIMPLE)[source]

Realized volatility of price series

Parameters:
  • x (Series) – time series of prices

  • w (Union[Window, int, str]) – Window or int: size of window and ramp up to use. e.g. Window(22, 10) where 22 is the window size and 10 the ramp up value. If w is a string, it should be a relative date like ‘1m’, ‘1d’, etc. Window size defaults to length of series.

  • returns_type (Returns) – returns type: simple, logarithmic or absolute

Return type:

Series

Returns:

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 return on time \(t\) based on returns_type

Type

Description

simple

Simple geometric change in asset prices: \(R_t = \frac{X_t}{X_{t-1}} - 1\) where \(X_t\) is the asset price at time \(t\)

logarithmic

Natural logarithm of asset price changes: \(R_t = log(X_t) - log(X_{t-1})\) where \(X_t\) is the asset price at time \(t\)

absolute

Absolute change in asset prices: \(Y_t = X_t - X_{t-obs}\) where \(X_t\) is the asset price at time \(t\)

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