gs_quant.timeseries.econometrics.correlation — gs_quant 0.1 documentation

# gs_quant.timeseries.econometrics.correlation

`correlation`(x, y, w=<gs_quant.timeseries.helper.Window object>, type_=<SeriesType.PRICES: 'prices'>)

  Rolling correlation of two price series

  Parameters

    - x (`Series`) – price series

    - y (`Series`) – price series

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

    - type – type of both input series: prices or returns

  Return type

    `Series`

  Returns

    date-based time series of correlation

  Usage

  Calculate rolling realized correlation, \(\rho_t\) of two price series over a given window:

  \(\rho_t = \frac{\sum_{i=t-w+1}^t (R_t - \overline{R_t})(Y_t - \overline{S_t})}{(N-1)\sigma R_t\sigma 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\)

  If prices are provided:

  \(R_t = \frac{X_t}{X_{t-1}} - 1\) and \(S_t = \frac{Y_t}{Y_{t-1}} - 1\)

  If returns are provided:

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

  \(\overline{R_t}\), \(\overline{S_t}\) are the mean values, and \(\sigma R_{t}\) and \(\sigma S_{t}\) are the sample standard deviations, of series \(R_t\) and \(S_t\) over the same window

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

  Examples

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

      >>> series1 = generate_series(100)
      >>> series2 = generate_series(100)
      >>> corr = correlation(series1, series2, 22)

  See also

  `std()` `returns()`