Denoised Covariance

The Denoised Covariance replaces the eigenvalues of the correlation matrix that random returns alone could produce by their average (Laloux, Cizeau, Potters and Bouchaud, 2000; López de Prado, 2020). Random matrix theory gives the range in which the eigenvalues of the correlation matrix of T periods of N unrelated returns fall; the eigenvalues within it carry noise, and those above it the structure of the market.

The formula for the 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 replaced by their average \(l_{\text{avg}}\), which keeps the trace, the total variance:

\[l_{k} = l_{\text{avg}} \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}}}\]

The signal eigenvectors and the total variance stay; what goes are the smallest eigenvalues, which make the inverse of the matrix, and with it optimized weights, chase estimation error.

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: constant residual eigenvalue method, random matrix theory cleaning, RMT covariance.

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

Which returns:

References

  • Paper Laloux, L., Cizeau, P., Potters, M. and Bouchaud, J.-P. (2000). “Random Matrix Theory and Financial Correlations.” International Journal of Theoretical and Applied Finance, 3(3), 391-397.
  • Paper López de Prado, M. (2020). “Machine Learning for Asset Managers.” Cambridge University Press, chapter 2.
  • Library Referenced against skfolio’s DenoiseCovariance (Denoised Covariance)
  • Library Referenced against Riskfolio-Lib’s denoiseCov (Spectral Denoised Covariance, Targeted Shrinkage Covariance)
  • Library Shares similar logic as RiskLabAI’s denoise_cov (Denoised Covariance)
Share