roll_information_coefficient¶
Defined in fynance.metrics
- roll_information_coefficient(pred, real, w=63, method='spearman')[source]
Trailing-window Information Coefficient.
A rolling view of the
fynance.metrics.information_coefficient: rather than one number over the whole sample, it reports how the predictive power evolves through time over a trailing window ofwbars. It is strictly causal — the value attuses only data on[t - w + 1, t]— so the firstw - 1entries arenp.nan.Two input shapes are supported:
1-D
(T,)— a single aligned(pred, real)time series; the value attis the IC computed over the trailing window[t - w + 1, t].2-D
(T, N)panel — the per-bar cross-sectional IC is computed first (across theNassets, one value per bar, reusinginformation_coefficient), then smoothed by a trailing mean overwbars (NaN bars are ignored within the window).
Alignment.
pred[t]is the score known attandreal[t]the outcome realized aftert.- Parameters:
- prednp.ndarray[dtype, ndim=1 or 2]
Predictions/scores. Same shape as
real.- realnp.ndarray[dtype, ndim=1 or 2]
Realized outcomes (e.g. forward returns).
- wint, optional
Trailing window length in bars (default
63), a positive integer.- method{‘spearman’, ‘pearson’}, optional
Correlation used for the IC —
'spearman'(default) for the rank-IC,'pearson'for the linear IC.
- Returns:
- np.ndarray[np.float64, ndim=1]
Trailing IC of shape
(T,); the firstw - 1entries arenp.nan.
See also
fynance.metrics.information_coefficient,ic_summary
Examples
On a monotone 1-D series every trailing window is perfectly ordered, so the rank-IC is
1once the window is full:>>> import numpy as np >>> pred = np.arange(10.) >>> real = np.arange(10.) >>> ic = roll_information_coefficient(pred, real, w=5) >>> bool(np.isnan(ic[:4]).all()) True >>> bool(np.allclose(ic[4:], 1.0)) True