qis.compute_ewm_vol¶
- qis.compute_ewm_vol(data, span=None, ewm_lambda=0.94, mean_adj_type=MeanAdjType.NONE, init_type=InitType.X0, init_value=None, apply_sqrt=True, annualize=False, annualization_factor=None, vol_floor_quantile=None, vol_floor_quantile_roll_period=1300, warmup_period=None, nan_backfill=NanBackfill.FFILL)[source]¶
exponentially weighted volatility, or variance when
apply_sqrtis False.Runs the EWM recursion on squared observations:
v_t = (1 - lambda) x_t^2 + lambda v_{t-1}, seeded before each column’s first finite observation, which then updates the seed; with the defaultX0seed the first variance is the first squared observation. Whether the result is a volatility per period or per annum depends onannualize, and the annualisation factor is inferred from the index frequency for pandas input.- Parameters:
data (DataFrame | Series | ndarray) – observations, time along the first axis
span (float | ndarray | None) – if given, overrides
ewm_lambdavialambda = 1 - 2 / (span + 1)ewm_lambda (float | ndarray) – decay in [0, 1); ignored when
spanis givenmean_adj_type (MeanAdjType) – how the mean is removed before squaring. NONE treats the data as already centred, which is the usual choice for returns
init_type (InitType) – how the recursion is seeded when
init_valueis None, on the scale of the squares:X0the first squared observation,ZEROzero,MEANthe full-sample mean square andVARthe full-sample variance of the observations (both look-ahead). It also seeds an EWMA mean adjustment, withVARread asMEANthereinit_value (float | ndarray | None) – explicit seed for the variance recursion, the state before the first observation
apply_sqrt (bool) – return volatility rather than variance
annualize (bool) – scale to annual terms
annualization_factor (float | None) – periods per year; inferred from the index for pandas input, and defaults to 1 with a warning for a bare ndarray
vol_floor_quantile (float | None) – floor the estimate at this rolling quantile of itself, so a quiet sample does not produce a vol that collapses toward zero. 0.16 is a usual choice. Works for a Series, a DataFrame and 1-d or 2-d arrays
vol_floor_quantile_roll_period (int) – lookback for that quantile, in periods
warmup_period (int | None) – number of leading observations set to nan, so an estimate is not reported before the recursion has data
nan_backfill (NanBackfill) – how the recursion carries over missing observations
- Returns:
volatility or variance, same container and shape as
data- Raises:
ValueError – if the selected span or decay is outside the stable EWM domain or its shape is incompatible with the data
- Return type: