Spectral Denoised Covariance

The Spectral Denoised Covariance sets the eigenvalues of the correlation matrix that random returns alone could produce to zero, so only the signal remains (López de Prado, 2020).

The formula for the Spectral Denoised 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}\]

The eigenvalues below the edge are set to zero:

\[l_{k} = 0 \quad \text{if } \lambda_{k} < \lambda_{\text{plus}}\] \[l_{k} = \lambda_{k} \quad \text{if } \lambda_{k} \geq \lambda_{\text{plus}}\]

The correlation matrix G is rebuilt from them and rescaled to a unit diagonal with the sample standard deviations \(s_{i}\):

\[G = \sum_{k=1}^{N} l_{k} \cdot v_{k} \cdot v'_{k}\] \[\Sigma_{i,j} = \frac{G_{i,j} \cdot s_{i} \cdot s_{j}}{\sqrt{G_{i,i} \cdot G_{j,j}}}\]

It keeps only the common factors, so the correlations of the assets come from their exposure to them; it needs at least one eigenvalue above the edge.

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: eigenvalue clipping, spectral denoising.

In the Finance Toolkit this is get_covariance_estimate with method="denoised_spectral", 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_spectral")

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