gs_quant.timeseries.econometrics.beta

beta(x, b, w=<gs_quant.timeseries.helper.Window object>, prices=True)[source]

Rolling beta of price series and benchmark

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

  • b (Series) – time series of benchmark prices

  • w (Union[Window, int, str]) – Window, int, or str: 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.

  • prices (bool) – True if input series are prices, False if they are returns

Return type:

Series

Returns:

date-based time series of beta

Usage

Calculate rolling beta, \(\beta_t\) of a series to a benchmark over a given window:

\(R_t = \alpha_t + \beta S_t + \epsilon_t\)

Calculated as:

\(\beta_t = \frac{\sum_{i=t-w+1}^t Cov(R_t, S_t)}{Var(S_t)}\)

where N is the number of observations in each rolling window, \(w\), and \(R_t\) and \(S_t\) are the simple returns for each series on time \(t\):

\(R_t = \frac{X_t}{X_{t-1}} - 1\) and \(S_t = \frac{b_t}{b_{t-1}} - 1\)

If prices = False, assumes returns are provided:

\(R_t = X_t\) and \(S_t = b_t\)

\(Cov(R_t, S_t)\) and \(Var(S_t)\) are the covariance and variance of the series \(R_t\) and \(S_t\) over the same window

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

Examples

Compute rolling \(1\) month (\(22\) business day) beta of two price series

>>> series = generate_series(100)
>>> benchmark = generate_series(100)
>>> b = beta(series, benchmark, 22)

See also

var() cov() correlation() returns()