qis.compute_ewm_xy_beta_tensor

qis.compute_ewm_xy_beta_tensor(x, y, span=None, ewm_lambda=0.94, warmup_period=20, is_x_correlated=True, nan_backfill=NanBackfill.FFILL)[source]

Compute an EWM beta tensor from factor and asset returns.

The cross moment E[x y'] and the factor second moment E[x x'] run the zero-seeded matrix recursion, which updates at the first row, and beta_t = E[x x']_t^{-1} E[x y']_t. The singularity test is scale free: a factor with a non-positive second moment gets NaN betas while the other factors are solved from the reduced system, and a reduced system whose unit-diagonal rescaling is numerically singular gives NaN betas. A beta is never replaced by the raw cross moment.

Parameters:
  • x (ndarray) – Factor returns with shape (time,) or (time, factors).

  • y (ndarray) – Asset returns with shape (time,) or (time, assets).

  • span (int | ndarray) – Optional EWM span overriding ewm_lambda.

  • ewm_lambda (float) – EWM decay when span is not supplied.

  • warmup_period (int) – Last time position masked during estimator warm-up.

  • is_x_correlated (bool) – Whether to invert the full factor cross-moment matrix; False uses its diagonal, one-factor betas for each factor.

  • nan_backfill (NanBackfill) – Missing-observation policy applied to both EWM moments in the beta ratio. NAN_FILL reports NaN where the factor or the asset is missing on that row.

Returns:

EWM betas with shape (time, factors, assets).

Raises:
  • TypeError – If an input is not one- or two-dimensional, or time dimensions differ.

  • ValueError – If the selected span or decay is outside the stable EWM domain.

Return type:

ndarray