quantlab.portfolio.predefined.ledoit_wolf.shrunk_low_rank#
- quantlab.portfolio.predefined.ledoit_wolf.shrunk_low_rank(window, covered)[source]#
Return
(a, U)witha I + U U'each bar’s Ledoit-Wolf estimate over its covered symbols.windowis[bars, n, symbols], finite wherecovered([bars, symbols]).sklearn.covariance.ledoit_wolfterm for term, on the demeaned windowX([n, p]per bar): the sample covarianceX'X / n, its mean variancemu, and the shrinkagemin(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.ais the shrinkage timesmuandUisX' 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