qis.compute_ewm_vector_autocorr

qis.compute_ewm_vector_autocorr(a, span=None, ewm_lambda=0.94, lag=1, is_normalize=True, nan_backfill=NanBackfill.FFILL, var_init_type=InitType.ZERO)[source]

EWM autocorrelation ratio of each column: EWM lagged moment over EWM second moment.

Runs g_t = lambda g_{t-1} + (1 - lambda) x_{t-lag} x_t and v_t = lambda v_{t-1} + (1 - lambda) x_t^2 from t = lag and returns g_t / v_t. The input is used as given (demean it first). Both states are seeded at zero by default, so the estimate dated t uses rows up to t only, the warm-up factor cancels in the ratio, and the result is the diagonal of compute_ewm_matrix_autocorr(). The ratio divides by the current second moment only, so it is not bounded by one.

Parameters:
  • a (ndarray) – demeaned observations, shape (t,) or (t, n)

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

  • ewm_lambda (float) – EWM decay, used when span is None

  • lag (int) – lag in rows

  • is_normalize (bool) – return the ratio; False returns g_t

  • nan_backfill (NanBackfill) – how a non-finite update is handled; by default both states carry forward

  • var_init_type (InitType) – seed of v. InitType.ZERO (default) is point in time; InitType.VAR seeds with the full-sample np.nanvar of each column, which looks ahead with a weight that decays like lambda^t

Returns:

shape (t, n), n being 1 for 1-d input; NaN for the first lag rows and wherever the second moment is not positive

Raises:

ValueError – if var_init_type is neither InitType.ZERO nor InitType.VAR

Return type:

ndarray