qis.compute_ewm

qis.compute_ewm(data, span=None, ewm_lambda=0.94, init_value=None, init_type=InitType.X0, is_unit_vol_scaling=False, nan_backfill=NanBackfill.FFILL)[source]

exponentially weighted moving average of a t-by-n panel.

Implements the recursion m_t = (1 - lambda) x_t + lambda m_{t-1}, evaluated column-wise by the numba kernel ewm_recursion(). The seed is the state before each column’s first finite observation, and that observation updates it, so with the default X0 seed the result is pandas ewm(adjust=False) column by column, however late a column starts. The container type of data is preserved.

Parameters:
  • data (DataFrame | Series | ndarray) – observations, time along the first axis

  • span (float | ndarray) – if given, overrides ewm_lambda via lambda = 1 - 2 / (span + 1), the same correspondence pandas uses

  • ewm_lambda (float | ndarray) – decay in [0, 1); higher is smoother. Ignored when span is given

  • init_value (float | ndarray | None) – explicit seed, the state before the first observation; overrides init_type

  • init_type (InitType) – how the seed is set when init_value is None — the first observation (X0), zero, or the full-sample mean (look-ahead); see InitType

  • is_unit_vol_scaling (bool) – rescale the output to unit unconditional variance

  • nan_backfill (NanBackfill) – how the recursion carries over missing observations

Returns:

smoothed data, same container and shape as data

Raises:

ValueError – if the selected span or decay is outside the stable EWM domain, the decay shape is incompatible with the data, or init_type is InitType.VAR

Return type:

DataFrame | Series | ndarray