gs_quant.timeseries.statistics.cov — gs_quant 0.1 documentation

# gs_quant.timeseries.statistics.cov

`cov`(x, y, w=<gs_quant.timeseries.helper.Window object>)

  Rolling co-variance of series over given window

  Parameters

    - x (`Series`) – series: timeseries

    - y (`Series`) – series: timeseries

    - 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.

  Return type

    `Series`

  Returns

    timeseries of covariance

  Usage

  Provides unbiased estimator of sample co-variance over a rolling window:

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

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

  \(\overline{X_t} = \frac{\sum_{i=t-w+1}^{t} X_i}{N}\) and \(\overline{Y_t} = \frac{\sum_{i=t-w+1}^{t} Y_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_x = generate_series(100)
      >>> prices_y = generate_series(100)
      >>> cov(returns(prices_x) returns(prices_y), 22)

  See also

  `sum()` `mean()` `var()`