#387·gs-quant

[BUG] correlation(x, y, assume_zero_mean=True) raises IndexError with the default window

Author: AstralchemistCreated Sep 28, 2026Updated Sep 28, 2026

Describe the bug correlation(x, y, assume_zero_mean=True) raises IndexError whenever it is called with the default window, for any pair of price series. In gs_quant/timeseries/econometrics.py the default window is sized on the price series by normalize_window(x, w) (60 for 60 prices), the returns are then aligned and dropna'd to 59 points, and volatility(returns, w, assume_zero_mean=True) hands a 60 wide window to std over 59 values. apply_ramp in helper.py returns an empty series when the window is longer than the input, and annualize then reads x.index[0] from it. The Pearson branch is fine because returns() keeps the leading NaN there, so prices and returns have the same length, and corr_swap_correlation is fine because it sizes its window as n_days - 1.

To Reproduce

python
import numpy as np, pandas as pd
from gs_quant.timeseries import econometrics as ec
idx = pd.bdate_range("2024-01-01", periods=60)
rng = np.random.default_rng(1)
x = pd.Series(100 * np.cumprod(1 + rng.normal(0, 0.01, 60)), index=idx)
y = pd.Series(100 * np.cumprod(1 + rng.normal(0, 0.01, 60)), index=idx)
print(ec.correlation(x, y).iloc[-1])                              # -0.085239
print(ec.correlation(x, y, 22, assume_zero_mean=True).iloc[-1])   #  0.04067
ec.correlation(x, y, assume_zero_mean=True)
# IndexError: index 0 is out of bounds for axis 0 with size 0

Expected behavior The zero mean correlation over the default window returns a value, the same way the Pearson branch does.

Screenshots Not applicable.

Systems setup:

  • OS: macOS 26 (Darwin 25.6.0), arm64
  • Python version: 3.12
  • GS-Quant version: 2.1.17, commit f2a505a; pandas 3.0.6, numpy 2.3.5

Additional context A one line fix is to normalise the window on the cleaned returns rather than on the prices, or to compute the annualisation factor once from the cleaned returns and pass it to volatility(..., annualization_factor=...), which also removes the second inference. test_econometrics.py never calls the zero mean branch without an explicit window, which is why the tests pass.