qis.compute_ewm_alpha_r2_given_prediction

qis.compute_ewm_alpha_r2_given_prediction(y_data, y_prediction, span=None, ewm_lambda=0.94, nan_backfill=NanBackfill.FFILL)[source]

EWM alpha and R-squared of a given prediction.

With e_t = y_t - prediction_t, alpha is alpha_t = EWM(e)_t (X0 seed) and R2_t = 1 - EWM((e - alpha)^2)_t / EWM((y - EWM(y))^2)_t, clipped to [0, 1] and NaN where the denominator is not positive. Both second moments start from a zero seed and are centred on contemporaneous EWMAs, so the ratio is an in-sample fit diagnostic, not an out-of-sample R-squared.

Parameters:
  • y_data (DataFrame) – realised values, one column per series

  • y_prediction (DataFrame) – predictions with the index and columns of y_data

  • span (float | ndarray) – if given, overrides ewm_lambda via lambda = 1 - 2 / (span + 1)

  • ewm_lambda (float | ndarray) – decay in [0, 1)

  • nan_backfill (NanBackfill) – missing-observation policy of every recursion

Returns:

the EWM alpha and the EWM R-squared, both with the index and columns of y_data

Return type:

Tuple[DataFrame, DataFrame]