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}. 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 Noneinit_value (float | ndarray | None) – explicit seed for the variance recursion
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
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- Return type: