qis.compute_returns_transform

qis.compute_returns_transform(returns, returns_transform=ReturnsTransform.ROLLING_RA_RETURNS, momentum_span=31, vol_span=33, rolling_ra_returns_span=31)[source]

apply the returns transform selected by returns_transform.

ROLLING_RA_RETURNS calls compute_rolling_ra_returns(span=rolling_ra_returns_span, weight_shift=1); EWMA_RETURNS_MOMENTUM calls compute_ewm_ra_returns_momentum( momentum_span, vol_span, weight_shift=1).

The defaults of this dispatcher, momentum_span=31 and vol_span=33, differ on purpose from those of compute_ewm_ra_returns_momentum (63 and 31): they make the two transforms comparable. An EWM of span 31 has mean age (31 - 1) / 2 = 15 rows, the same as the 31-row rolling window of ROLLING_RA_RETURNS, and span 33 gives the decay 1 - 2/34 = 0.941 of the RiskMetrics daily volatility (0.94). Pass the spans explicitly to reproduce the underlying function’s defaults.

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

  • returns_transform (ReturnsTransform) – the transform to apply

  • momentum_span (int) – EWM span of the momentum filter of EWMA_RETURNS_MOMENTUM

  • vol_span (int) – EWM span of the volatility normaliser of EWMA_RETURNS_MOMENTUM

  • rolling_ra_returns_span (int) – summation window, in rows, of ROLLING_RA_RETURNS

Returns:

the transformed returns, in the shape of returns

Raises:

TypeError – for a returns_transform that is not implemented

Return type:

DataFrame