qis.adjust_returns_with_joint_unsmoothing¶
- qis.adjust_returns_with_joint_unsmoothing(returns, factor_returns, span=40, mean_adj_type=MeanAdjType.NONE, warmup_period=4, max_ar_coeff=0.75, min_ar_coeff=0.0, max_factor_beta=1.0, min_factor_beta=0.0, apply_ewma_mean_smoother=False, return_diagnostics=False)[source]¶
Jointly EWMA-fit phi_1 (own-lag) and beta_1 (lagged factor) and unsmooth.
The fitted model is
r[t] = phi1 * r[t-1] + beta1 * F[t-1] + e[t]. The inversion isr_u[t] = (r[t] - phi1 * r[t-1] + beta1 * (F[t] - F[t-1])) / (1 - phi1).Fits phi_1 and beta_1 in one regression of r_t on [r_{t-1}, F_{t-1}] with a time-varying bounded EWMA beta pair. When a bound binds, the other coefficient is re-estimated conditional on it, rather than clipped independently. Lags the pair one period to avoid look-ahead, and applies the mean-preserving inversion on the raw levels. Single-stage counterpart to running
adjust_returns_with_arthenadjust_returns_with_factor_lag, without the omitted-variable bias in the AR step or the order dependence.- Parameters:
returns (DataFrame) – Observed period returns (rows = dates, columns = assets), in the reference currency. Every column passed is unsmoothed; exclude liquid columns upstream.
factor_returns (Series) – The liquid factor return (e.g. the MATF Equity factor), same index and frequency as
returns.span (int) – EWMA span in observations, default 40 (ten years at QE). Monthly callers must explicitly use span=120 and warmup_period=12.
mean_adj_type (MeanAdjType) – Default NONE fits raw r_t, r_{t-1}, F_{t-1}. Explicit EWMA uses a point-in-time
InitType.ZEROseed. Inversion always uses raw returns; time-varying coefficients need not preserve the sample mean.warmup_period (int | None) – Number of jointly observable coefficient dates masked once per asset. The application lag then makes the next return the first corrected one. Default 4; None disables the warmup mask.
max_ar_coeff (float) – Upper cap on phi_1, strictly < 1, bounding the inflation factor 1 / (1 - phi_1). Default 0.75 caps this multiplier at 4x.
min_ar_coeff (float | None) – Lower cap on phi_1, default 0.0. None disables.
max_factor_beta (float | None) – Upper cap on beta_1, default 1.0. None disables.
min_factor_beta (float | None) – Lower cap on beta_1. Default 0.0 floors the lagged-factor beta at non-negative (the forward-only re-timing the factor-lag engine enforces via its sign tie). Bounds are imposed jointly in the weighted fit; None disables this bound.
apply_ewma_mean_smoother (bool) – If True, apply an extra EWMA smoother to each coefficient series after the bounded fit. Default False.
return_diagnostics (bool) – If True, return
(corrected, phi_1, beta_1), the unsmoothed returns and the two rolling coefficient panels.
- Returns:
Unsmoothed returns (DataFrame, input shape). If
return_diagnostics, the tuple(corrected, phi_1, beta_1).- Raises:
ValueError – if
span <= 0,warmup_period < 0,factor_returnsis not an aligned Series,max_ar_coeff >= 1, or bounds are invalid.- Return type: