quantlab.portfolio.predefined.ledoit_wolf.shrunk_low_rank#

quantlab.portfolio.predefined.ledoit_wolf.shrunk_low_rank(window, covered)[source]#

Return (a, U) with a I + U U' each bar’s Ledoit-Wolf estimate over its covered symbols.

window is [bars, n, symbols], finite where covered ([bars, symbols]). sklearn.covariance.ledoit_wolf term for term, on the demeaned window X ([n, p] per bar): the sample covariance X'X / n, its mean variance mu, and the shrinkage min(beta, delta) / delta, every sum over [p, p] taken on the [n, n] Gram matrix instead; one covered symbol gets no shrinkage, as sklearn’s own special case. a is the shrinkage times mu and U is X' sqrt((1 - shrinkage) / n), zero on the uncovered symbols.

Examples

>>> from sklearn.covariance import ledoit_wolf
>>> x = np.random.default_rng(0).normal(size=(20, 5))
>>> shift, exposures = shrunk_low_rank(x[None], np.ones((1, 5), dtype=bool))
>>> bool(np.allclose(exposures[0] @ exposures[0].T + shift[0] * np.eye(5), ledoit_wolf(x)[0]))
True