Targeted Shrinkage Covariance
The Targeted Shrinkage Covariance shrinks the part of the correlation matrix that random returns alone could produce towards its own diagonal, and leaves the signal part as it is (López de Prado, 2020).
The formula for the Targeted Shrinkage Covariance starts from the eigenvalues \(\lambda_{k}\) and eigenvectors \(v_{k}\) of the sample correlation matrix (ddof=1) and the upper edge \(\lambda_{\text{plus}}\) of the Marcenko-Pastur distribution, with \(\sigma^{2}\) the variance of the noise, fitted so that the Marcenko-Pastur density matches the eigenvalues:
\[\lambda_{\text{plus}} = \sigma^{2} \cdot \left(1 + \sqrt{\frac{N}{T}}\right)^{2}\]It splits the correlation matrix into the signal part \(C_{s}\) of the K eigenvalues above the edge and the noise part \(C_{n}\) of the rest:
\[C_{s} = \sum_{k=1}^{K} \lambda_{k} \cdot v_{k} \cdot v'_{k}\] \[C_{n} = \sum_{k=K + 1}^{N} \lambda_{k} \cdot v_{k} \cdot v'_{k}\]It keeps a share a of the noise part and replaces the rest by its diagonal, Diag(C_n), then rescales to a unit diagonal with the sample standard deviations \(s_{i}\):
\[G = C_{s} + a \cdot C_{n} + (1 - a) \cdot \text{Diag}(C_{n})\] \[\Sigma_{i,j} = \frac{G_{i,j} \cdot s_{i} \cdot s_{j}}{\sqrt{G_{i,i} \cdot G_{j,j}}}\]With \(a = 0\) the noise keeps only its contribution to the variances, with \(a = 1\) the estimate is the sample covariance itself.
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: targeted shrinkage denoising.
In the Finance Toolkit this is get_covariance_estimate with method="denoised_shrink", 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="denoised_shrink")
| 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.0776 | 0.0529 | 0.0139 | 0.0255 |
| MSFT | 0.0529 | 0.0661 | 0.0121 | 0.0222 |
| JNJ | 0.0139 | 0.0121 | 0.0280 | 0.0058 |
| XOM | 0.0255 | 0.0222 | 0.0058 | 0.0730 |
4 rows
References
- Paper López de Prado, M. (2020). “Machine Learning for Asset Managers.” Cambridge University Press, chapter 2.
- Library Referenced against Riskfolio-Lib’s denoiseCov (Spectral Denoised Covariance, Targeted Shrinkage Covariance)