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 of w bars. It is strictly causal — the value at t uses only data on [t - w + 1, t] — so the first w - 1 entries are np.nan.

Two input shapes are supported:

  • 1-D (T,) — a single aligned (pred, real) time series; the value at t is 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 the N assets, one value per bar, reusing information_coefficient), then smoothed by a trailing mean over w bars (NaN bars are ignored within the window).

Alignment. pred[t] is the score known at t and real[t] the outcome realized after t.

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 first w - 1 entries are np.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 1 once 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