denoise_cov

Defined in fynance.portfolio.covariance

denoise_cov(sigma, n_obs, method='clip')[source]

Marchenko-Pastur eigenvalue clipping on the correlation matrix.

Converts sigma to a correlation matrix, replaces the “noise” eigenvalues (those at or below the Marchenko-Pastur upper edge \(\lambda_+ = (1 + \sqrt{q})^2\), \(q = N / n\_obs\)) by their mean (trace-preserving), reconstructs, forces a unit diagonal and rescales back by the original volatilities.

Parameters:
sigmaarray_like

Symmetric (N, N) covariance matrix to denoise.

n_obsint

Number of observations the covariance was estimated on.

method{‘clip’}, optional

Denoising method. Only 'clip' (constant-residual-eigenvalue) is implemented; the keyword is validated so the signature is stable for future methods. Default 'clip'.

Returns:
np.ndarray

Symmetric (N, N) denoised covariance matrix, same diagonal and trace as sigma.

References

[1]

V.A. Marchenko, L.A. Pastur, “Distribution of eigenvalues for some sets of random matrices”, Mat. Sb., 72(114), 1967, 507-536.

[2]

M. Lopez de Prado, “Machine Learning for Asset Managers”, Cambridge University Press, 2020 (constant residual eigenvalue method).

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> X = rng.standard_normal((60, 10))
>>> S = sample_cov(X, ddof=0)
>>> D = denoise_cov(S, n_obs=60)
>>> D.shape
(10, 10)
>>> bool(np.allclose(np.diag(D), np.diag(S)))
True