qis.compute_ewm_beta_alpha_forecast

qis.compute_ewm_beta_alpha_forecast(x_data, y_data, span=None, ewm_lambda=0.94, mean_adj_type=MeanAdjType.NONE, init_type=InitType.X0, beta_init_value=None, annualize=False, nan_backfill=NanBackfill.FFILL)[source]

Compute one-factor EWMA beta, alpha, one-step-ahead prediction and diagnostics.

Beta is the ratio of exponentially weighted cross-moments, beta_t = E[x y]_t / E[x^2]_t, and alpha the EWMA of the fitted residual y_t - beta_t x_t; both are dated t and use the observation at t. The prediction is the forecast of y_t from information up to t-1 and the factor return at t, beta_{t-1} x_t + alpha_{t-1}, and is NaN on the first row. The residual variance and the R-squared are in-sample diagnostics of the fitted residual y_t - beta_t x_t - alpha_t.

With the default InitType.X0 every recursion is seeded with its first observation, so every output is point in time. InitType.MEAN and InitType.VAR seed with full-sample statistics (look-ahead in the first 1.5 N rows).

When beta_init_value is supplied, the first jointly finite, nonzero factor observation x_f is replaced by a one-observation beta prior: both moments are seeded with it and the pair (x_f, y_f) is replaced by (x_f, beta_init_value * x_f), so the observed y_f does not enter. The first finite beta equals the prior, which then keeps weight lambda^(t-f) in both moments and fades as later observations update the recursion, without look-ahead.

Parameters:
  • x_data (DataFrame | Series) – Factor-return Series, or one factor-return column per asset.

  • y_data (DataFrame) – Asset-return columns.

  • span (float | ndarray) – EWMA span. Overrides ewm_lambda when supplied.

  • ewm_lambda (float | ndarray) – EWMA decay used when span is None.

  • mean_adj_type (MeanAdjType) – Mean-adjustment convention; INSAMPLE is forward-looking.

  • init_type (InitType) – Seed of every recursion when no beta prior is given; see InitType.

  • beta_init_value (float | ndarray | None) – Optional scalar or per-asset initial beta prior.

  • annualize (bool) – Whether to annualize factor and residual variances.

  • nan_backfill (NanBackfill) – Missing-observation convention of every recursion.

Returns:

Beta, alpha, prediction, factor variance (one column per asset), residual variance and R-squared frames, all with the index and columns of y_data.

Raises:
  • ValueError – If beta_init_value cannot broadcast to the asset columns or contains a non-finite value.

  • IndexError – If paired factor and asset frames have different column counts.

  • NotImplementedError – If the input container combination is unsupported.

Return type:

Tuple[DataFrame, DataFrame, DataFrame, DataFrame, DataFrame, DataFrame]