qis.compute_ewm_covar_tensor

qis.compute_ewm_covar_tensor(a, span=None, ewm_lambda=0.94, covar0=None, is_corr=False, nan_backfill=NanBackfill.DEFLATED_FFILL)[source]

exponentially weighted covariance matrix at every date, as a 3-d tensor.

The path version of compute_ewm_covar(): same recursion, but every intermediate state is kept rather than only the last. Memory is t * n * n floats, so this is for rolling risk attribution over a modest universe, not for a wide panel.

Parameters:
  • a (ndarray) – observations, shape (t, n); 1-d input is rejected

  • span (int | ndarray) – if given, overrides ewm_lambda via lambda = 1 - 2 / (span + 1)

  • ewm_lambda (float) – decay in [0, 1); ignored when span is given

  • covar0 (ndarray) – seed matrix, shape (n, n); zeros when None

  • is_corr (bool) – normalise each matrix to a correlation matrix

  • nan_backfill (NanBackfill) – how a missing observation is carried, entry by entry. The default DEFLATED_FFILL treats it as a zero observation and keeps every matrix positive semidefinite; FFILL can break that when gaps differ across assets. NAN_FILL reports NaN at the entries of the assets missing on that row

Returns:

covariance tensor, shape (t, n, n), one matrix per observation date

Raises:

ValueError – if the selected span or decay is outside the stable EWM domain, or a is not 2-d

Return type:

ndarray