Skip to content
All library documents

Matching Portfolio Variance Across Sample Estimators

Article Quant Q&A · Author: develarist

Summary

The document addresses why the variance of a weighted return series may differ from the variance calculated from an asset covariance matrix. Its example compares a default variance calculation on portfolio returns with the quadratic form of the sample covariance matrix. The stated explanation is that the two calculations use different sample estimators: the default variance function uses a biased estimator, while the covariance calculation uses the unbiased sample estimator.

To make the results agree, the answer sets the variance function’s degrees-of-freedom adjustment to use the unbiased estimator, matching the convention used to construct the covariance matrix. The principle is to align estimator conventions when comparing the two forms of portfolio variance. This resolves the discrepancy in the example, but the document does not discuss other possible causes, such as inconsistent observations, missing data, or differing return alignment.

Key ideas

  • Portfolio variance from a weighted return series can be compared with the covariance-matrix quadratic form.
  • The two results may differ when their sample estimators use different degrees-of-freedom conventions.
  • Use the same unbiased sample variance convention as the covariance matrix to align the calculations.
  • The explanation assumes both calculations use the same returns and portfolio weights.

Tags

Full text
# For portfolio variance, why doesn't $Var(X w) = w^\top \Sigma w$?


# For portfolio variance, why doesn't $Var(X w) = w^\top \Sigma w$?












From multivariate asset returns $X$, we can calculate the sample covariance matrix $\Sigma$.

The definition of (any) portfolio variance is $w^\top \Sigma w$, where $w$ are portfolio weights.

If $X w$ is the portfolio-weighted asset returns series (a vector), shouldn't the variance of this vector of portfolio returns be equal to the variance of the portfolio, $w^\top \Sigma w$?

When I calculate both of them for the same dataset and weights, why don't they equal? $$Var(X w) \neq w^\top \Sigma w$$

```
import numpy as np
from numpy.random import randn

X = randn(1000,3)           #3 assets with 1000 return observations
Sigma = np.cov(X.T)         #covariance matrix
w = np.array([0.2,0.3,0.5]) #portfolio weights for 3 assets

print(np.var(X@w))          #this should equal the next line but doesn't
print(w@Sigma@w)
```

## Answer by Pleb (score 5, accepted)

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

I'm not a Python programmer, however, reading the reference manual of np.var, you're using the "biased" version of the variance estimator. Instead use the unbiased variance estimator:

```
import numpy as np
from numpy.random import randn

X = randn(1000,3)           
Sigma = np.cov(X.T)         
w = np.array([0.2,0.3,0.5]) 

print(np.var(X@w, ddof=1))
print((w@Sigma)@w)
```

where "ddof=1" gives the unbiased variance estimator (see link). This should help.

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.