Ledoit-Wolf Shrinkage
The Ledoit-Wolf Shrinkage pulls the sample covariance towards the identity matrix scaled by the average variance, with the shrinkage intensity that minimizes the expected squared (Frobenius) distance to the true covariance matrix (Ledoit and Wolf, 2004). The target has no estimation error and the sample covariance no bias, and the mix keeps the matrix well-conditioned.
The formula for the Ledoit-Wolf Shrinkage starts from the sample covariance S of the demeaned returns \(y_{i , t}\) of the N assets over the T periods, divided by T, and the target F, the identity matrix I times the average variance nu:
\[S_{i,j} = \frac{\sum_{t=1}^{T} y_{i,t} \cdot y_{j,t}}{T}\] \[\nu = \frac{\sum_{i=1}^{N} S_{i,i}}{N}\] \[F = \nu \cdot I\]The intensity delta compares the variance of the entries of S, \(b^{2}\), with their squared distance from the target, \(d^{2}\):
\[b^{2} = \frac{\sum_{t=1}^{T} \sum_{i=1}^{N} \sum_{j=1}^{N} (y_{i,t} \cdot y_{j,t} - S_{i,j})^{2}}{N \cdot T^{2}}\] \[d^{2} = \frac{\sum_{i=1}^{N} \sum_{j=1}^{N} (S_{i,j} - F_{i,j})^{2}}{N}\] \[\delta = \frac{\min\left(b^{2}, d^{2}\right)}{d^{2}}\]The estimate moves S that share of the way to the target:
\[\Sigma = (1 - \delta) \cdot S + \delta \cdot F\]A delta close to 0 means the sample covariance is precise enough on its own, one close to 1 that the history cannot tell the assets apart. The target treats every asset as equally volatile and unrelated, so it also pulls the correlations towards zero.
Its parameters can be set, and it can be shown as a correlation matrix. The covariance matrix holds the variance of every asset and the covariance of every pair, the risk input of the mean-variance analysis of Markowitz (1952). With N assets it holds N (N + 1) / 2 numbers to estimate, and when N is not small compared to the number of periods T, the sample estimate is noisy and ill-conditioned: its smallest eigenvalues come out too small, and an optimizer that inverts it puts large weights on the combinations of assets that only look safe in the sample. The estimators differ in how they deal with this: by shrinking towards a structured target, by cleaning the eigenvalues, by weighting recent periods, by counting only large moves or by resisting outliers. Every estimate is annualized with the number of periods in a year.
Also known as: Ledoit-Wolf covariance, shrunk covariance, shrinkage towards the identity.
In the Finance Toolkit this is get_covariance_estimate with method="ledoit_wolf", the same function as Covariance Estimate.
Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_covariance_estimate:
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "JNJ", "XOM"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.portfolio.get_covariance_estimate(method="ledoit_wolf")
| Parameter | Type | Description | Example |
|---|---|---|---|
method | str | The estimator. Options are: “sample” (Sample Covariance, ddof=1), “ledoit_wolf” (Ledoit-Wolf Shrinkage, towards the scaled identity, Ledoit and Wolf, 2004), “ledoit_wolf_constant_correlation” (Ledoit-Wolf Constant Correlation Shrinkage, towards the average correlation, Ledoit and Wolf, 2004), “ledoit_wolf_single_factor” (Ledoit-Wolf Single Factor Shrinkage, towards the covariance that the benchmark as a single factor implies, Ledoit and Wolf, 2003), “oas” (Oracle Approximating Shrinkage, Chen et al., 2010), “shrunk” (Fixed Shrinkage, 10% towards the scaled identity by default), “semicovariance” (Semicovariance, the co-movement below a zero return, Estrada, 2008), “exponential” (Exponentially Weighted Covariance, recent periods weigh most, RiskMetrics), “denoised” (Denoised Covariance, the eigenvalues of the correlation matrix that random returns could produce averaged, Laloux et al., 2000), “denoised_spectral” (Spectral Denoised Covariance, those eigenvalues set to zero), “denoised_shrink” (Targeted Shrinkage Covariance, the noise correlations shrunk towards their diagonal, López de Prado, 2020), “gerber” (Gerber Covariance, co-movements beyond half a standard deviation, Gerber et al., 2022), “detoned” (Detoned Covariance, the correlation without its first principal components, López de Prado, 2020), “factor” (Factor Model Covariance, the covariance a time series factor model implies, Connor, 1995), “minimum_covariance_determinant” (Minimum Covariance Determinant, the reweighted covariance of the half of the periods with the smallest covariance determinant, robust to outliers, Rousseeuw and Van Driessen, 1999), “jlogo” (j-LoGo Covariance, the sparse inverse covariance on the TMFG planar graph of the correlations, Barfuss et al., 2016), “geodesic” (Geodesic Shrinkage, 10% towards the scaled identity along the geodesic of the positive definite matrices by default, Bhatia, 2007), “regime_adjusted_ew” (Regime Adjusted Exponentially Weighted Covariance, a half-life of 40 periods by default, rescaled by the recent realized against predicted risk, Paleologo, 2025), “denoised_detoned” (Denoised and Detoned Covariance, the denoised correlation with its first principal components removed, López de Prado, 2020), “nercome” (Nonparametric Eigenvalue-Regularized Covariance Matrix Estimator, eigenvectors from one part of the periods and the variances along them from the other, Lam, 2016), “ccc_garch” (Constant Conditional Correlation GARCH Covariance, the next-period covariance of GARCH volatilities with constant correlations, Bollerslev, 1990), “mm” (MM-Estimator, robust, Maronna et al., 2019), “rocke” (Rocke S-Estimator, robust, Maronna et al., 2019). Defaults to “sample”. | "sample" |
period | str | The frequency of the returns. Options are: “daily” (daily returns), “weekly” (weekly returns), “monthly” (monthly returns), “quarterly” (quarterly returns), “yearly” (yearly returns). Defaults to “daily”. | "weekly" |
span | int | The span in periods of the exponentially weighted estimate. Defaults to 180. | 180 |
shrinkage | float | The fixed intensity \(\delta\) of the fixed and geodesic shrinkage, between 0 and 1. Defaults to 0.1 (PyPortfolioOpt defaults to 0.2 for the fixed shrinkage). | |
gerber_threshold | float | The threshold of the Gerber estimate in standard deviations, between 0 and 1. Defaults to 0.5. | 0.5 |
gerber_statistic | int | The Gerber statistic. Options are: 0 (the original statistic), 1 (the positive semidefinite variant), 2 (the matrix form). Defaults to 1. | 1 |
denoise_alpha | float | The share \(\alpha\) of the noise correlations the targeted shrinkage keeps, between 0 and 1. Defaults to 0. | 0 |
components | int | The number of principal components the detoned estimates remove. Defaults to 1. | 1 |
factor_selection | str | How the factor estimate takes the loadings. Options are: “ols” (every factor), “forward” (stepwise by the p-values, 0.05), “backward” (stepwise by the p-values, 0.05), “pcr” (principal components regression keeping 95% of the variance). Defaults to “ols”. | "ols" |
factors | pd.DataFrame | None | The factor returns of the factor estimate, one column per factor, at the frequency of the period. Defaults to None, the Fama and French five factors of the region. | None, the Fama and French five factors of the region |
region | str | The region of the Fama and French factors. Options are: “United States”, “Developed”, “Developed ex US”, “Europe”, “Japan”, “Asia Pacific ex Japan”, “North America”. Defaults to “United States”. | "Europe" |
half_life | float | The half-life in periods of the exponential weights of the regime adjusted estimate. Defaults to 40, skfolio’s default as well. | 40, skfolio's default as well |
seed | int | None | The seed of the random subsets of the Minimum Covariance Determinant, which also starts the MM and Rocke estimators, and of the random splits of NERCOME (numpy’s default generator), so the same returns give the same estimate. Defaults to 0. | 42 |
correlation | bool | Whether to return the correlation matrix of the estimate instead. Defaults to False. | False |
include_benchmark | bool | Whether to include the benchmark as an asset. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
Which returns:
| Item | AAPL | MSFT | JNJ | XOM |
|---|---|---|---|---|
| AAPL | 0.0772 | 0.0442 | 0.0070 | 0.0139 |
| MSFT | 0.0442 | 0.0659 | 0.0032 | 0.0057 |
| JNJ | 0.0070 | 0.0032 | 0.0288 | 0.0059 |
| XOM | 0.0139 | 0.0057 | 0.0059 | 0.0727 |
4 rows
References
- Paper Ledoit, O. and Wolf, M. (2004). “A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices.” Journal of Multivariate Analysis, 88(2), 365-411.
- Library Referenced against scikit-learn’s LedoitWolf (Ledoit-Wolf Shrinkage)
- Library Shares similar logic as PyPortfolioOpt’s CovarianceShrinkage.ledoit_wolf (Ledoit-Wolf Shrinkage, Ledoit-Wolf Constant Correlation Shrinkage, Ledoit-Wolf Single Factor Shrinkage)