Skip to content
All library documents

Diagnosing Negative Portfolio Variance from an Invalid Covariance Matrix

Article Quant Q&A · Author: rmacey

Summary

The document explains why a portfolio variance or tracking-error variance calculated as a quadratic form can be negative: the input covariance matrix may fail to be positive semidefinite, so it is not a valid covariance matrix. A valid covariance matrix must produce a nonnegative value for every portfolio weight vector. The discussion warns that this is an economic consistency problem as well as a numerical one, since a matrix of pairwise correlations can encode relationships that cannot all hold together.

Suggested remedies include building the matrix from nonnegative asset variances and a positive-definite correlation matrix, shrinking estimates toward a target, or repairing the matrix by changing its eigenvalues. The questioner’s simulated tracking errors support their expectation that the portfolio difference has positive variance, but simulations do not fix an invalid matrix. The advice is general; the document does not diagnose the particular matrix or compare repair methods’ effects on portfolio weights and risk estimates.

Key ideas

  • A covariance matrix must be positive semidefinite for every portfolio variance to be nonnegative.
  • A negative quadratic-form result indicates that the supplied matrix is not a valid covariance matrix or has a computational issue.
  • Pairwise correlations that seem plausible individually may be jointly inconsistent.
  • Possible repairs include covariance shrinkage or replacing negative eigenvalues, though the chosen repair can affect risk estimates.

Tags

Full text
# Negative variance?


# Negative variance?












Using the formula w*Cov*t(w) I can generate a negative portfolio variance. What are the implications of a negative variance? Should I just assume it's zero? A negative variance is troublesome because one cannot take the square root (to estimate standard deviation) of a negative number without resorting to imaginary numbers. It also doesn't seem consistent with the formula for variance which is the average of the squared deviations from the mean since squaring always produces a positive number.

The negative variance is the tip of the iceberg of my real problem. I have a covariance matrix representing (ex-ante) expectations. I do not have and do not wish to use historical returns. I have 23 asset classes. I've been playing around with some portfolio optimization (not mean variance). I come up with a set of weights (w) for an optimal portfolio. I also have a set of weights for my benchmark (b). I'm calculating a tracking error. The square of the tracking error should be (w-b) * cov * t(w-b). This is what is negative.

Further, my weights are sufficiently different from my benchmark that inspection and intuition tell me zero is the wrong answer. To further prove this I generated 1000 random returns (using my assumptions for return and the covariance matrix) for the asset classes and calculated 1000 returns for w and for b. Then I calculated the difference and then I took the variance. And since I have a computer I repeated this 1000 times. The lowest tracking error (square root of the variance of the differences) was 2.7%. So I'm confident that the variance should be positive.

FWIW, I have a 23x23 covariance matrix. Most of it comes from a public source (Research Affiliates). I add municipal bonds. I'm pretty happy with the covariance matrix in that other uses for it - e.g. the portfolio variance of w and of b seem to be great.

Any insight into either what I might be doing wrong either computationally or by interpretation would be appreciated. All my work is in R and I could share some data and code.

## Answer by Richi Wa (score 3)

https://quant.stackexchange.com/a/40121

As pointed out by other users here your designed covariance matrix appearantly is not positive-definite and therefore you get this strange behaviour.

Please note that this is not just a mathematical problem but an economic one.

As a toy example look at this: If A and B are strongly negatively correlated (say -1) then they can not both be negatively correlated (again -1) to a third one C. You can design (=write down) such a matrix but this is something you can not encounter in correct maths or real life.

What you can do:

- Pick non-negative variances for each asset $V = diag(v_1,v_2,\ldots, v_n)$

- choose a positive-definite matrix for the correlations $C$

- Calculate $Cov = \sqrt{V} C \sqrt{V}$ where the square-root is componentwise.

The calculation in the third step is discussed on stack.overflow. The package corpcor offers ways to shrink covariances to chosen targets and offers checks for positive-definiteness.

The function `make.positive.definite` is available that finds the closest (in a chosen sense) positive-definite matrix to some given one.

## Answer by Enrico Schumann (score 1)

https://quant.stackexchange.com/a/40110

As Ivan pointed out in his comment, your matrix is not a valid covariance matrix. Put differently, there exists no data set (with complete observations) from which you could have estimated such a covariance matrix.

The simplest way to repair such a matrix is to replace the negative eigenvalues of the matrix by zeros. This method is implemented in function `repairMatrix` in the R package NMOF, which I maintain.

## Answer by rmacey (score 0)

https://quant.stackexchange.com/a/40106

Ivan's comment is a good answer. I'm adding something but mainly creating an answer instead of a comment to make sure search results show there is an answer. My covariance matrix should be positive semi definite. As I understand it, this roughly translates to it being like a non-negative number. When you multiply by it, you will get zero or something with the same sign. Here is a link to a brief explanation of positive semi definite and positive definite that I found useful. Thanks Ivan.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.