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_tis the per-period EWM volatility of the supplied returns, sovol_targetis a volatility per period of the same grid: an annual targetsigma_annualis passed assigma_annual / sqrt(af), for example0.15 / np.sqrt(252)on business-day returns.vol_target=0.15on 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_lambdavia1 - 2 / (span + 1). May be an array with one entry per columnewm_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.NONEby default, sosigmais the root of an EWM second moment about zeroinit_value (float | ndarray | None) – explicit seed of the variance recursion; the first squared return by default
vol_floor_quantile (float | None) – floor
sigmaat this rolling quantile of itself; None disables itvol_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) - 1before scaling, while the volatility is still estimated on the supplied (log) returnsweight_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_volalready lagged byweight_lag(dated at the return they scale), and the unlagged per-period EWM volatility. The target weight to execute at t isvol_target / ewm_volat t, not the laggedweights- Return type:
the triple
(ra_returns, weights, ewm_vol)