qis.unsmooth_returns_glm¶
- qis.unsmooth_returns_glm(returns, ar_order=3, theta=None, return_diagnostics=False)[source]¶
Apply static AR(q) unsmoothing following Getmansky-Lo-Makarov (2004).
Fits a single AR(q) model over the entire sample to extract constant smoothing weights, then inverts period-by-period:
r*_t = (r_t - Σ_i θ_i r_{t-i}) / (1 - Σ_i θ_i). Less adaptive than the rolling EWMA method but useful for academic reproducibility.Pass
thetato supply the smoothing weights instead of estimating them. Use that when the coefficient comes from outside the series - a panel estimate pooled across vintages, or a value fixed for a production run so the unsmoothing does not move with the aggregation choice. No model is fitted in that case, so the length guard does not apply and the same weights apply to every column of a DataFrame.- Parameters:
returns (Series | DataFrame) – Observed return Series or DataFrame.
ar_order (int) – Lag order q. Standard values: 2 for monthly, 3 for higher frequency. Ignored when
thetais given, where the order is the length oftheta.theta (float | ndarray | None) – Fixed smoothing weights, a scalar for AR(1) or an array of length q. When None the weights are estimated from the sample.
return_diagnostics (bool) – If True, return tuple of (unsmoothed, diagnostics).
- Returns:
Unsmoothed returns in the same shape as input. If
return_diagnostics, a tuple withGLMUnsmoothingDiagnostics(single) or dict (per column).- Raises:
ValueError – If returns has fewer than 4*ar_order observations and
thetais None, or if a suppliedthetasums to within 1e-10 of 1.- Return type:
Series | DataFrame | Tuple[Series, GLMUnsmoothingDiagnostics] | Tuple[DataFrame, dict]
Note
Prefer
adjust_returns_with_arfor most practical applications. Use this method for academic reproducibility or single-parameter summaries.When
theta_sumexceeds 1 the denominator turns negative and the inversion flips the sign of the unsmoothed series.is_severeflags|theta_sum| > 0.95; check it before using the result.An observation whose lags are not all observed cannot be inverted and is returned as NaN, not as the raw value: an uncorrectable observation is missing, not unsmoothed.