quantlab.model.evaluation.volatility_level_metrics#
- quantlab.model.evaluation.volatility_level_metrics(pred, target)[source]#
Return the level metrics of a volatility prediction,
qlikeandvariance_ratio.Both compare predicted and realised variance on the cells where the prediction and the target are finite and positive (a non-positive volatility has no variance ratio).
qlikeis the mean over those cells ofq - log(q) - 1withq = target**2 / pred**2: zero for a perfect prediction, and it penalises an under-prediction of variance more than an over-prediction of the same size; a prediction close to zero where the target is not makes it very large, and infinite (written as null in a run’srun.json) onceqoverflows, which flags a model predicting next to no risk.variance_ratioismean(target**2) / mean(pred**2), pooled over cells, so the most volatile symbols weigh most: 1 when the predicted variance is unbiased, above 1 when risk is under-predicted.- Parameters:
- predarray_like
A 2-D
[T, S]panel of predicted volatilities.- targetarray_like
A 2-D
[T, S]panel of realised volatilities, on the same scale.
- Returns:
- dict[str, float]
{"qlike": ..., "variance_ratio": ...}, NaN without a usable cell.
Examples
A prediction of half the realised volatility on every cell, so a quarter of its variance:
>>> volatility_level_metrics([[0.1, 0.2]], [[0.2, 0.4]]) {'qlike': 1.6137056388801092, 'variance_ratio': 4.0}