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 residualy_t - beta_t x_t; both are datedtand use the observation att. The prediction is the forecast ofy_tfrom information up tot-1and the factor return att,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 residualy_t - beta_t x_t - alpha_t.With the default
InitType.X0every recursion is seeded with its first observation, so every output is point in time.InitType.MEANandInitType.VARseed with full-sample statistics (look-ahead in the first1.5 Nrows).When
beta_init_valueis supplied, the first jointly finite, nonzero factor observationx_fis 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 observedy_fdoes not enter. The first finite beta equals the prior, which then keeps weightlambda^(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_lambdawhen supplied.ewm_lambda (float | ndarray) – EWMA decay used when
spanis None.mean_adj_type (MeanAdjType) – Mean-adjustment convention;
INSAMPLEis 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_valuecannot 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]