qis.compute_ra_returns

qis.compute_ra_returns(returns, span=None, ewm_lambda=0.94, vol_target=None, mean_adj_type=MeanAdjType.NONE, init_value=None, vol_floor_quantile=None, vol_floor_quantile_roll_period=1300, warmup_period=None, is_log_returns_to_arithmetic=False, weight_lag=1)[source]

divide returns by a lagged EWM volatility: ra_t = vol_target * r_t / sigma_(t - weight_lag).

The volatility is never annualised. sigma_t is the per-period EWM volatility of the supplied returns, so vol_target is a volatility per period of the same grid: an annual target sigma_annual is passed as sigma_annual / sqrt(af), for example 0.15 / np.sqrt(252) on business-day returns. vol_target=0.15 on daily returns targets 15% per day.

Parameters:
  • returns (Series | DataFrame) – periodic returns, one column per asset

  • span (float | ndarray) – EWM span of the volatility; overrides ewm_lambda via 1 - 2 / (span + 1). May be an array with one entry per column

  • ewm_lambda (float | ndarray) – EWM decay of the volatility, 0.94 (RiskMetrics) by default

  • vol_target (float | None) – volatility target per period of the return grid. None means a unit target, so the output is in units of risk, not unscaled returns

  • mean_adj_type (MeanAdjType) – mean removed before the second moment; MeanAdjType.NONE by default, so sigma is the root of an EWM second moment about zero

  • init_value (float | ndarray | None) – explicit seed of the variance recursion; the first squared return by default

  • vol_floor_quantile (float | None) – floor sigma at this rolling quantile of itself; None disables it

  • vol_floor_quantile_roll_period (int) – rolling window of the floor quantile, in rows

  • warmup_period (int | None) – number of leading finite volatility estimates set to missing

  • is_log_returns_to_arithmetic (bool) – map the returns to exp(r) - 1 before scaling, while the volatility is still estimated on the supplied (log) returns

  • weight_lag (int | None) – rows between the volatility estimate and the return it scales; 1 by default, so the scale is known before the return. None or 0 divides a return by a volatility that already contains it

Returns:

the scaled returns, the weights vol_target / ewm_vol already lagged by weight_lag (dated at the return they scale), and the unlagged per-period EWM volatility. The target weight to execute at t is vol_target / ewm_vol at t, not the lagged weights

Return type:

the triple (ra_returns, weights, ewm_vol)