Detoned Covariance

The Detoned Covariance removes the first principal components of the correlation matrix, the market, and rescales the rest to a unit diagonal (López de Prado, 2020). The market component makes all assets look alike; without it, the groups of assets that move together for other reasons stand out.

The formula for the Detoned Covariance starts from the eigenvalues \(\lambda_{k}\) and eigenvectors \(v_{k}\) of the sample correlation matrix C (ddof=1), largest first, and removes the first m of them:

\[G = C - \sum_{k=1}^{m} \lambda_{k} \cdot v_{k} \cdot v'_{k}\]

It rescales the result to a unit diagonal with the sample standard deviations \(s_{i}\):

\[\Sigma_{i,j} = \frac{G_{i,j} \cdot s_{i} \cdot s_{j}}{\sqrt{G_{i,i} \cdot G_{j,j}}}\]

The matrix has rank N - m, so it is singular: it suits clustering, as the detoned codependence, but an optimizer cannot invert it.

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: detoned correlation, market-removed correlation.

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

Which returns:

References

  • Paper López de Prado, M. (2020). “Machine Learning for Asset Managers.” Cambridge University Press, chapter 2.
  • Library Referenced against skfolio’s DetoneCovariance (Detoned Covariance)
Share