ledoit_wolf¶
Defined in fynance.portfolio.covariance
- ledoit_wolf(X, target='const_corr')[source]
Ledoit-Wolf linear shrinkage covariance estimator.
Closed-form convex combination \((1 - \delta) S + \delta F\) of the sample covariance \(S\) and a low-variance target \(F\), with the shrinkage intensity \(\delta \in [0, 1]\) chosen to minimize the asymptotic expected Frobenius loss. Well conditioned even when \(N\) is comparable to or larger than \(T\) (where the plain sample covariance is singular or ill-conditioned).
- Parameters:
- Xarray_like
Returns panel, shape
(T,)or(T, N).- target{‘const_corr’, ‘identity’, ‘diag’}, optional
Shrinkage target:
'const_corr'— constant-correlation matrix built from the mean off-diagonal correlation (Ledoit & Wolf, 2004b).'identity'— mean-variance scaled identity (Ledoit & Wolf, 2004a).'diag'—diag(S), i.e. shrink off-diagonal entries only.
Default
'const_corr'.
- Returns:
- np.ndarray
Symmetric
(N, N)shrunk covariance matrix.
References
[1]O. Ledoit, M. Wolf, “A well-conditioned estimator for large-dimensional covariance matrices”, Journal of Multivariate Analysis, 88(2), 2004, 365-411.
[2]O. Ledoit, M. Wolf, “Honey, I shrunk the sample covariance matrix”, The Journal of Portfolio Management, 30(4), 2004, 110-119.
Examples
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> X = rng.standard_normal((50, 4)) >>> S = ledoit_wolf(X) >>> S.shape (4, 4) >>> bool(np.allclose(S, S.T)) True