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")

Which returns:

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)
Share