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 isalpha_t = EWM(e)_t(X0seed) andR2_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_dataspan (float | ndarray) – if given, overrides
ewm_lambdavialambda = 1 - 2 / (span + 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: