Covariance Estimate

Estimate the annualized covariance matrix of the assets, with one of the estimators the optimizers take.

Its parameters can be set, and it can be shown as a correlation matrix.

  • Sample: the sample covariance (ddof=1).
  • Ledoit-Wolf, Ledoit-Wolf constant correlation, Ledoit-Wolf single factor and Oracle Approximating Shrinkage: shrinkage with an estimated intensity (Ledoit and Wolf, 2003, 2004; Chen et al., 2010).
  • Fixed shrinkage: \(\Sigma = (1 - \delta) S + \delta\) (tr(S) / N) I with a fixed intensity \(\delta\), the shrinkage.
  • Semicovariance: the co-movement below a zero return (Estrada, 2008).
  • Exponential: exponentially weighted with \(\alpha = 2\) / (span + 1) (RiskMetrics).
  • Denoised: the eigenvalues of the correlation matrix below the Marčenko-Pastur upper edge averaged (constant residual eigenvalue), set to zero (spectral), or their part of the correlation shrunk towards its diagonal (targeted shrinkage), C_signal + \(\alpha\) C_noise + (\(1 - \alpha\)) diag(C_noise) with \(\alpha\) the denoise alpha (López de Prado, 2020).
  • Gerber: \(\Sigma = D G D\) with G the Gerber statistic of the moves beyond the Gerber threshold in standard deviations: statistic \(0 (n_{c} - n_{d}) / (n_{c} + n_{d})\), \(1 (n_{c} - n_{d}) / (T - n_{n})\) or 2 H / √(diag(H) diag(H)’) (Gerber et al., 2022).
  • Detoned: the first principal components of the correlation matrix, the market, removed and the rest rescaled to a unit diagonal (López de Prado, 2020). It is singular, so the optimizers do not take it; it suits clustering as the detoned codependence.
  • Factor: \(\Sigma = B \sum_{f} B' + D\), the covariance a time series factor model implies, with B the loadings of the assets on the factors (the Fama and French five factors by default), \(\sum_{f}\) the covariance of the factors and D the variances of the residuals, all with ddof=1 (Fama and French, 1993; Connor, 1995). The loadings come from OLS on every factor, a stepwise selection or a principal components regression (see get_factor_loadings), on the periods both the assets and the factors have.
  • Minimum Covariance Determinant: the covariance of the h = ⌈(T + N + 1) / 2⌉ periods whose covariance matrix has the smallest determinant, found with the C-steps of FAST-MCD from random subsets (with the seed), made consistent at the normal distribution and reweighted: the periods with a Mahalanobis distance below the 97.5% quantile of \(\chi_{N}^{2}\) are kept and their covariance is multiplied by \(c = 0.975 / F_{N + 2} (\chi_{N}^{2} (0.975))\) (Rousseeuw and Van Driessen, 1999; Croux and Haesbroeck, 1999). Crashes and data errors barely move it.
  • j-LoGo: \(\Sigma = J^{- 1}\) with \(J = \Sigma_{C} [S_{\text{CC}}]^{- 1} - \Sigma_{S} [S_{\text{SS}}]^{- 1}\) the sparse inverse covariance over the 4-cliques C and separators S of the Triangulated Maximally Filtered Graph of the similarities \((1 + \rho) / 2\), a planar graph with 3(N - 2) links (Massara et al., 2017; Barfuss et al., 2016). With four or fewer assets every pair is linked and it is the sample covariance.
  • Geodesic: \(\Sigma = S^{\tfrac{1}{2}} (S^{- \tfrac{1}{2}} T S^{- \tfrac{1}{2}})^{\delta} S^{\tfrac{1}{2}}\) with T = (tr(S) / N) I and \(\delta\) the shrinkage, which keeps the eigenvectors of S and interpolates its eigenvalues geometrically, \(\lambda^{1 - \delta}\) (tr(S) / N)^δ (Bhatia, 2007; Musolas et al., 2021).
  • Regime adjusted exponentially weighted: \(\phi^{2} S_{T}\) with \(S_{t} = \lambda S_{t - 1} + (1 - \lambda) r_{t} r_{t}'\) (around zero, bias-corrected, \(\lambda\) = 2^(-1 / half_life)) and \(\phi\) the exponential average (half-life half_life / 2) of \(\vert w' r_{t} \vert / \sqrt{w' S_{t - 1} w} / \sqrt{2 / \pi}\) for the inverse volatility portfolio w, clipped to [0.7, 1.6] (Paleologo, 2025).
  • Denoised and detoned: the denoised correlation with its first principal components removed and rescaled to a unit diagonal, the order of López de Prado (2020, section 2.6). Singular, like the detoned estimate.
  • NERCOME: \(\Sigma = (1 / M) \sum_{s} P_{1}\) diag(P_1’ \(S_{2} P_{1}\)) P_1’ over \(M = 50\) random splits of the periods into a first part of m and the rest, with \(P_{1}\) the eigenvectors of the first part’s sample covariance and \(S_{2}\) the second part’s: eigenvalues that are not fitted to the same noise as the eigenvectors (Abadir, Distaso and Žikeš, 2014; Lam, 2016). m is chosen from \(2 \sqrt{T}\), 0.2T, …, 0.8T, \(T - 2.5 \sqrt{T}\) and \(T - 1.5 \sqrt{T}\) by the smallest \(\text{‖} \text{avg} (\sum_{m} - S_{2}) \text{‖}^{2}\) (Lam, 2016), and the splits drawn with the seed.
  • CCC-GARCH: the next-period covariance of the constant conditional correlation model of Bollerslev (1990), \(\Sigma_{T} + 1 = D R D\) with D the GARCH(1, 1) volatilities forecast for the next period, \(\sigma_{i,T}^{2} + 1 = \omega_{i} + \alpha_{i} \epsilon_{i,T}^{2} + \beta_{i} \sigma_{i,T}^{2}\), and R the correlation of the standardized residuals \(\epsilon_{t} / \sigma_{t}\) of the returns around their average. It follows the volatility now, not its average over the history.
  • MM-estimator: robust to almost half the periods being outliers and 95% as efficient in its shape (the correlations and variance ratios) as the sample covariance for normal returns: an S-estimator with Tukey’s bisquare \(\rho (d) = 1 - (1 - (d / c)^{2})^{3}\) (the scatter with the smallest scale s solving avg \(\rho (d_{t} / \sqrt{s}) = (1 - N / T) / 2\)), followed by a bisquare M-step with a larger c at that scale (Tatsuoka and Tyler, 2000; Salibián-Barrera, Van Aelst and Willems, 2006). Both are iteratively reweighted means and covariances, with weights that fall to zero for periods far from the bulk.
  • Rocke’s S-estimator: the translated biweight of Rocke (1996) on the squared distances, \(\rho (x) = ((x - 1) / (4 \gamma)) (3 - ((x - 1) / \gamma)^{2})\) + ½ within \(\gamma\) of 1 (0 below, 1 above), with \(\gamma = \min (\chi_{N}^{2} (0.995) / N - 1 , 1)\), made consistent at the normal distribution through the median distance, which keeps its robustness for many assets (Maronna, Martin, Yohai and Salibián-Barrera, 2019).

Also known as: covariance estimator, risk model, shrunk covariance, Gerber covariance, denoised covariance, detoned correlation, factor covariance, factor risk model, robust covariance, MCD, FastMCD, TMFG, LoGo, sparse inverse covariance, geodesic shrinkage, regime adjusted EWMA covariance, short-term volatility update, NERCOME, split-sample covariance, CCC-GARCH, constant conditional correlation, MM-estimator, S-estimator, Rocke estimator, translated biweight.

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

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What is the annualized Gerber covariance matrix of Apple, Microsoft, Johnson & Johnson and ExxonMobil, based on 2021 to 2025?

Which returns:

Parameters

get_covariance_estimate accepts the following parameters.

ParameterTypeDescriptionExample
methodstrThe estimator. Options are: “sample” (the sample covariance, ddof=1), “ledoit_wolf” (shrunk towards the scaled identity, Ledoit and Wolf, 2004), “ledoit_wolf_constant_correlation” (shrunk towards the average correlation, Ledoit and Wolf, 2004), “ledoit_wolf_single_factor” (shrunk towards the covariance that the benchmark as a single factor implies, Ledoit and Wolf, 2003), “oas” (Oracle Approximating Shrinkage, Chen et al., 2010), “shrunk” (a fixed 10% towards the scaled identity), “semicovariance” (the co-movement below a zero return, Estrada, 2008), “exponential” (exponentially weighted, recent periods weigh most, RiskMetrics), “denoised” (the eigenvalues of the correlation matrix that random returns could produce averaged, Laloux et al., 2000), “denoised_spectral” (those eigenvalues set to zero), “denoised_shrink” (the noise correlations shrunk towards their diagonal, López de Prado, 2020), “gerber” (co-movements beyond half a standard deviation, Gerber et al., 2022), “detoned” (the correlation without its first principal components, López de Prado, 2020), “factor” (the covariance a time series factor model implies, Connor, 1995), “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” (the sparse inverse covariance on the TMFG planar graph of the correlations, Barfuss et al., 2016), “geodesic” (10% towards the scaled identity along the geodesic of the positive definite matrices, Bhatia, 2007), “regime_adjusted_ew” (exponentially weighted with a half-life of 40 periods, rescaled by the recent realized against predicted risk, Paleologo, 2025), “denoised_detoned” (the denoised correlation with its first principal components removed, López de Prado, 2020), “nercome” (eigenvectors from one part of the periods and the variances along them from the other, averaged over random splits, Lam, 2016), “ccc_garch” (the next-period covariance of GARCH(1, 1) volatilities with constant correlations, Bollerslev, 1990), “mm” (the robust MM-estimator, Maronna et al., 2019), “rocke” (Rocke’s robust S-estimator, Maronna et al., 2019). Defaults to “sample”."sample"
periodstrThe 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"
spanintThe span in periods of the exponentially weighted estimate. Defaults to 180.180
shrinkagefloatThe 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_thresholdfloatThe threshold of the Gerber estimate in standard deviations, between 0 and 1. Defaults to 0.5.0.5
gerber_statisticintThe Gerber statistic. Options are: 0 (the original statistic), 1 (the positive semidefinite variant), 2 (the matrix form). Defaults to 1.1
denoise_alphafloatThe share \(\alpha\) of the noise correlations the targeted shrinkage keeps, between 0 and 1. Defaults to 0.0
componentsintThe number of principal components the detoned estimates remove. Defaults to 1.1
factor_selectionstrHow 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"
factorspd.DataFrame | NoneThe 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
regionstrThe 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_lifefloatThe 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
seedint | NoneThe 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
correlationboolWhether to return the correlation matrix of the estimate instead. Defaults to False.False
include_benchmarkboolWhether to include the benchmark as an asset. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding.2
show_columnsstr | list[str] | NoneThe 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

References

  • Paper Ledoit, O. and Wolf, M. (2004). “A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices.” Journal of Multivariate Analysis, 88(2), 365-411.
  • Paper Gerber, S., Markowitz, H. M., Ernst, P. A., Miao, Y., Javid, B. and Sargen, P. (2022). “The Gerber Statistic: A Robust Co-Movement Measure for Portfolio Optimization.” The Journal of Portfolio Management, 48(3), 87-102.
  • Paper López de Prado, M. (2020). “Machine Learning for Asset Managers.” Cambridge University Press, chapter 2.
  • Paper Fama, E. F. and French, K. R. (1993). “Common Risk Factors in the Returns on Stocks and Bonds.” Journal of Financial Economics, 33(1), 3-56.
  • Paper Connor, G. (1995). “The Three Types of Factor Models: A Comparison of Their Explanatory Power.” Financial Analysts Journal, 51(3), 42-46.
  • Paper Rousseeuw, P. J. and Van Driessen, K. (1999). “A Fast Algorithm for the Minimum Covariance Determinant Estimator.” Technometrics, 41(3), 212-223.
  • Paper Croux, C. and Haesbroeck, G. (1999). “Influence Function and Efficiency of the Minimum Covariance Determinant Scatter Matrix Estimator.” Journal of Multivariate Analysis, 71(2), 161-190.
  • Paper Massara, G. P., Di Matteo, T. and Aste, T. (2017). “Network Filtering for Big Data: Triangulated Maximally Filtered Graph.” Journal of Complex Networks, 5(2), 161-178.
  • Paper Barfuss, W., Massara, G. P., Di Matteo, T. and Aste, T. (2016). “Parsimonious Modeling with Information Filtering Networks.” Physical Review E, 94(6), 062306.
  • Paper Bhatia, R. (2007). “Positive Definite Matrices.” Princeton University Press.
  • Paper Musolas, A., Smith, S. T. and Marzouk, Y. (2021). “Geodesically Parameterized Covariance Estimation.” SIAM Journal on Matrix Analysis and Applications, 42(2), 528-556.
  • Paper Paleologo, G. A. (2025). “The Elements of Quantitative Investing.” Wiley Finance.
  • Paper Abadir, K. M., Distaso, W. and Žikeš, F. (2014). “Design-Free Estimation of Variance Matrices.” Journal of Econometrics, 181(2), 165-180.
  • Paper Lam, C. (2016). “Nonparametric Eigenvalue-Regularized Precision or Covariance Matrix Estimator.” The Annals of Statistics, 44(3), 928-953.
  • Paper Bollerslev, T. (1990). “Modelling the Coherence in Short-Run Nominal Exchange Rates: A Multivariate Generalized ARCH Model.” The Review of Economics and Statistics, 72(3), 498-505.
  • Paper Rocke, D. M. (1996). “Robustness Properties of S-Estimators of Multivariate Location and Shape in High Dimension.” The Annals of Statistics, 24(3), 1327-1345.
  • Paper Tatsuoka, K. S. and Tyler, D. E. (2000). “On the Uniqueness of S-Functionals and M-Functionals under Nonelliptical Distributions.” The Annals of Statistics, 28(4), 1219-1243.
  • Paper Salibián-Barrera, M., Van Aelst, S. and Willems, G. (2006). “Principal Components Analysis Based on Multivariate MM Estimators with Fast and Robust Bootstrap.” Journal of the American Statistical Association, 101(475), 1198-1211.
  • Paper Maronna, R. A., Martin, R. D., Yohai, V. J. and Salibián-Barrera, M. (2019). “Robust Statistics: Theory and Methods (with R).” 2nd edition, Wiley.
  • Library Referenced against scikit-learn’s LedoitWolf
  • Library Referenced against scikit-learn’s OAS
  • Library Referenced against PyPortfolioOpt’s CovarianceShrinkage.shrunk_covariance
  • Library Referenced against PyPortfolioOpt’s semicovariance
  • Library Referenced against PyPortfolioOpt’s exp_cov
  • Library Referenced against skfolio’s DenoiseCovariance (constant residual eigenvalue)
  • Library Referenced against Riskfolio-Lib’s denoiseCov (spectral and targeted shrinkage)
  • Library Referenced against skfolio’s GerberCovariance (statistics 1 and 2)
  • Library Referenced against Riskfolio-Lib’s gerber_cov_stat0 (statistic 0)
  • Library Referenced against skfolio’s DetoneCovariance (sample covariance)
  • Library Referenced against Riskfolio-Lib’s risk_factors (factor)
  • Library Referenced against Riskfolio-Lib’s loadings_matrix (backward selection, every factor kept)
  • Library Referenced against scikit-learn’s MinCovDet
  • Library Referenced against Riskfolio-Lib’s covar_matrix (j-LoGo)
  • Library Referenced against skfolio’s GeodesicShrinkageCovariance
  • Library Referenced against skfolio’s RegimeAdjustedEWCovariance (its defaults)
  • Library Shares similar logic as PyPortfolioOpt’s CovarianceShrinkage.ledoit_wolf
  • Library Shares similar logic as PyPortfolioOpt’s CovarianceShrinkage.oracle_approximating
  • Library Shares similar logic as scikit-learn’s ShrunkCovariance
  • Library Shares similar logic as skfolio’s ShrunkCovariance
  • Library Shares similar logic as Riskfolio-Lib’s covar_matrix (fixed shrinkage)
  • Library Shares similar logic as RiskLabAI’s denoise_cov
  • Library Shares similar logic as Riskfolio-Lib’s gerber_cov_stat1 (statistic 1)
  • Library Shares similar logic as Riskfolio-Lib’s gerber_cov_stat2 (statistic 2)
  • Library Shares similar logic as skfolio’s FactorModel (factor)
  • Library Shares similar logic as RiskLabAI’s nercome_denoised_covariance
  • Library Shares similar logic as PortfolioAnalytics (R)’s CCCgarch.MM
  • Library Shares similar logic as PortfolioAnalytics (R)’s custom.covRob.MM
  • Library Shares similar logic as PortfolioAnalytics (R)’s custom.covRob.Rocke
Share