[BUG] annualize and prices docstrings describe a different calculation from the code
Describe the bug
Two docstrings in gs_quant/timeseries/econometrics.py describe a calculation the code does not do.
annualizesays it is "useful for annualizing daily or monthly returns" and gives the exampleannualize(returns(prices)), but the function multiplies by the square root of the annualisation factor. That is the scaling for a volatility. A mean return annualises by the factor itself, so a user following the docstring gets a number that is off bysqrt(F). On a random daily series the example yields a "mean annual return" of about -0.021 wheremean * 252is about -0.333.pricesgives the formulaY_t = (1 + X_{t-1}) Y_{t-1}, but the code computesproduct(1 + series) * initial, which isY_t = (1 + X_t) Y_{t-1}. The index in the formula is off by one.
To Reproduce
import numpy as np, pandas as pd
from gs_quant.timeseries import econometrics as ec
px = pd.Series(100 * np.cumprod(1 + np.random.default_rng(3).normal(0.0005, 0.012, 120)), index=pd.bdate_range("2024-01-01", periods=120))
r = ec.returns(px).dropna()
print(ec.annualize(r).mean()) # about -0.021, mean return times sqrt(252)
print(r.mean() * 252) # about -0.333, what "annualised return" meansExpected behavior
The annualize docstring restricted to inputs with a volatility dimension, or the function offered a returns mode that multiplies by F. The prices formula written as Y_t = (1 + X_t) Y_{t-1}.
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
The annualize point was also part of the closed PR #362, which its author withdrew without review.
Source: goldmansachs/gs-quant