Unit 1, lesson 6

Linear algebra for covariance and hedging

Proves that covariance matrices are positive semidefinite, uses eigenvalues and the spectral theorem to find directions of risk, and solves minimum-error hedges by orthogonal projection and the pseudoinverse.

  • Video 6
  • Calculus, linear algebra, optimization and probability

A desk wants to offset the risk of a position with two traded instruments whose gains are correlated with the position and with each other. Which holdings leave the smallest remaining variance, and what happens when the two instruments are nearly or exactly duplicates of each other? This lesson proves that covariance matrices are positive semidefinite, reads directions of risk from eigenvalues, derives the normal equations of the minimum-error hedge from orthogonal projection, and uses the pseudoinverse when the hedge system is singular.

Key terms

Covariance matrix

Definition All expectations on this page are under one fixed probability measure, for example the physical measure P\mathbb{P}. Let R=(R1,…,Rd)⊤R = (R_1, \dots, R_d)^{\top} be a random vector, such as the gains of dd instruments over one period, with E[Ri2]<∞E[R_i^2] < \infty for every ii, and let μ=E[R]\mu = E[R]. Its covariance matrix is the d×dd \times d matrix

Σ=E[(R−μ)(R−μ)⊤],\Sigma = E\bigl[(R - \mu)(R - \mu)^{\top}\bigr],

with the expectation taken entry by entry, so that Σij=Cov⁡(Ri,Rj)\Sigma_{ij} = \operatorname{Cov}(R_i, R_j) and Σii=Var⁡(Ri)\Sigma_{ii} = \operatorname{Var}(R_i). The finite second moments make every entry finite, since ∣Cov⁡(Ri,Rj)∣≤Var⁡(Ri)Var⁡(Rj)\lvert \operatorname{Cov}(R_i, R_j) \rvert \le \sqrt{\operatorname{Var}(R_i) \operatorname{Var}(R_j)}. Each entry is the expectation of a product of two scalar deviations, which commute, so Σij=Σji\Sigma_{ij} = \Sigma_{ji} and Σ\Sigma is symmetric. This is the population covariance of the model. The sample covariance of observations r1,…,rnr_1, \dots, r_n with mean rˉ\bar{r},

Σ^=1n−1∑k=1n(rk−rˉ)×(rk−rˉ)⊤,\begin{aligned} \hat{\Sigma} &= \frac{1}{n - 1} \sum_{k=1}^{n} (r_k - \bar{r}) \\[0.4em] &\qquad \times (r_k - \bar{r})^{\top}, \end{aligned}

is an estimate of it and a different object. Its rank is at most n−1n - 1, so it is singular whenever n≤dn \le d.

In plain words The diagonal holds the variance of each instrument, and the off-diagonal entries say how pairs of instruments move together. The matrix is a single object, and its entries cannot be chosen freely, as the next card shows.

Example Two constructed hedge instruments have centered gains with variances 44 and 44 and covariance 22, in squared currency units, so

Σ=[4224],\Sigma = \begin{bmatrix} 4 & 2 \\ 2 & 4 \end{bmatrix},

and their correlation is 2/4⋅4=0.52/\sqrt{4 \cdot 4} = 0.5. In a different setting, a sample covariance of d=3d = 3 returns computed from n=2n = 2 observations has rank at most 11 and is singular, whatever the population covariance is.

Positive semidefinite matrix

Definition A real symmetric d×dd \times d matrix AA is positive semidefinite if w⊤Aw≥0w^{\top} A w \ge 0 for every w∈Rdw \in \mathbb{R}^d, and positive definite if w⊤Aw>0w^{\top} A w > 0 for every w≠0w \ne 0. Every covariance matrix is positive semidefinite. For fixed weights ww, the portfolio w⊤Rw^{\top} R has the centered value w⊤(R−μ)w^{\top}(R - \mu), and

w⊤Σw=∑i,jwiwjΣij=E[(w⊤(R−μ))2]=Var⁡(w⊤R)≥0,\begin{aligned} w^{\top} \Sigma w &= \sum_{i,j} w_i w_j \Sigma_{ij} \\[0.4em] &= E\bigl[\bigl(w^{\top}(R - \mu)\bigr)^2\bigr] \\[0.4em] &= \operatorname{Var}(w^{\top} R) \ge 0 , \end{aligned}

where the middle equality is linearity of expectation applied to the double sum ∑i,jwiwj(Ri−μi)(Rj−μj)\sum_{i,j} w_i w_j (R_i - \mu_i)(R_j - \mu_j), which is the square of w⊤(R−μ)w^{\top}(R - \mu). The matrix Σ\Sigma is positive definite exactly when no nonzero ww makes w⊤Rw^{\top} R equal to a constant with probability 11.

In plain words A covariance matrix produces the variance of every portfolio of its instruments, and a variance cannot be negative. Correlations that each lie between −1-1 and 11 do not guarantee this, because all of them must fit together.

Example Give three instruments unit variances and every pairwise correlation −0.6-0.6. Each entry is a legal correlation, yet the equal holdings w=1=(1,1,1)w = \mathbf{1} = (1, 1, 1) give

w⊤Σw=3+6⋅(−0.6)=−0.6<0,\begin{aligned} w^{\top} \Sigma w &= 3 + 6 \cdot (-0.6) \\[0.4em] &= -0.6 < 0 , \end{aligned}

so no random vector has this covariance matrix. With three unit variances and one common correlation ρ\rho, the matrix is positive semidefinite exactly when −12≤ρ≤1-\tfrac12 \le \rho \le 1, so three instruments cannot all be strongly negatively correlated with one another.

Eigenvalues, eigenvectors and the spectral theorem

Definition A number λ\lambda is an eigenvalue of a square matrix AA, with eigenvector q≠0q \ne 0, if Aq=λqAq = \lambda q. The spectral theorem for real symmetric matrices, stated here without proof, says that a real symmetric d×dd \times d matrix AA has real eigenvalues λ1,…,λd\lambda_1, \dots, \lambda_d, listed with multiplicity, and an orthogonal matrix QQ, with Q⊤Q=IQ^{\top} Q = I, whose columns q1,…,qdq_1, \dots, q_d are corresponding unit eigenvectors, so that

A=QΛQ⊤,Λ=diag⁡(λ1,…,λd).\begin{gathered} A = Q \Lambda Q^{\top}, \\[0.4em] \Lambda = \operatorname{diag}(\lambda_1, \dots, \lambda_d). \end{gathered}

Then for every w∈Rdw \in \mathbb{R}^d,

w⊤Aw=∑j=1dλj (qj⊤w)2,w^{\top} A w = \sum_{j=1}^{d} \lambda_j \, (q_j^{\top} w)^2 ,

so AA is positive semidefinite exactly when every λj≥0\lambda_j \ge 0, and positive definite exactly when every λj>0\lambda_j > 0. For a covariance matrix, λj=qj⊤Σqj\lambda_j = q_j^{\top} \Sigma q_j is the variance of the portfolio with holding vector qjq_j. An eigenvalue 00 means that qj⊤(R−μ)=0q_j^{\top}(R - \mu) = 0 with probability 11, a combination that carries no risk in this model. That is a statement about the model’s random vector, not about every source of risk in a real position.

In plain words The eigenvectors of a covariance matrix are perpendicular directions of holdings that do not interact, and each eigenvalue is the variance per unit of squared holding size in its direction. Any portfolio splits into exposures to these directions, and its variance is the sum of the squared exposures weighted by the eigenvalues.

Example For the matrix with rows (4,2)(4, 2) and (2,4)(2, 4), multiplying by (1,1)(1, 1) gives (6,6)(6, 6) and multiplying by (1,−1)(1, -1) gives (2,−2)(2, -2). The eigenvalues are 66 and 22, with unit eigenvectors q1=(1,1)/2q_1 = (1, 1)/\sqrt{2} and q2=(1,−1)/2q_2 = (1, -1)/\sqrt{2}. The holdings w=(12,12)w = (\tfrac12, \tfrac12) have exposures 1/21/\sqrt{2} and 00, so their variance is 6⋅12=36 \cdot \tfrac12 = 3, and directly 14(4+2+2+4)=3\tfrac14(4 + 2 + 2 + 4) = 3. The spread w=(1,−1)w = (1, -1) has exposures 00 and 2\sqrt{2}, so its variance is 2⋅2=42 \cdot 2 = 4, and directly 4+4−2⋅2=44 + 4 - 2 \cdot 2 = 4. The spread shows the larger variance only because its holdings are larger. Per unit of squared holding size, its direction carries variance 22 against 66 for the equal-weight direction.

Orthogonal projection

Definition Let XX and Y1,…,YmY_1, \dots, Y_m be random variables with mean zero and finite second moments, and use the inner product ⟨U,W⟩=E[UW]\langle U, W \rangle = E[UW], which for centered variables is Cov⁡(U,W)\operatorname{Cov}(U, W). The hedge span is the set of payoffs h⊤Y=∑ihiYih^{\top} Y = \sum_i h_i Y_i with h∈Rmh \in \mathbb{R}^m. A payoff PP in the span is the orthogonal projection of XX onto the span if the residual X−PX - P is orthogonal to every YiY_i, that is, E[(X−P)Yi]=0E[(X - P) Y_i] = 0 for i=1,…,mi = 1, \dots, m. Then the residual is orthogonal to every payoff dd in the span, and

E[(X−P−d)2]=E[(X−P)2]+E[d2],\begin{aligned} &E\bigl[(X - P - d)^2\bigr] \\[0.4em] &= E\bigl[(X - P)^2\bigr] + E[d^2], \end{aligned}

because the cross term −2E[(X−P)d]-2E[(X - P)d] vanishes. So PP has the smallest mean squared error among all payoffs in the span, and any other payoff P+dP + d with the same error has E[d2]=0E[d^2] = 0, so it equals PP with probability 11. A projection always exists, as the pseudoinverse card shows, even when the holdings that produce it are not unique.

In plain words Think of payoffs as vectors whose squared length is their mean square. The best approximation of the target by hedge payoffs is the foot of the perpendicular, and the residual left over is uncorrelated with every hedge instrument. Moving away from the foot adds a second, perpendicular piece of error. This is the same geometry as least squares, with expectations in place of sums over observations.

Example A constructed target XX has variance 55, and one hedge gain YY has variance 44 and covariance 33 with XX. The payoff P=34YP = \tfrac34 Y leaves the residual X−34YX - \tfrac34 Y, whose covariance with YY is 3−34⋅4=03 - \tfrac34 \cdot 4 = 0, so it is the projection. Its error is

5−2⋅34⋅3+(34)2⋅4=5−4.5+2.25=2.75.\begin{aligned} &5 - 2 \cdot \tfrac34 \cdot 3 + \bigl(\tfrac34\bigr)^2 \cdot 4 \\[0.4em] &= 5 - 4.5 + 2.25 = 2.75 . \end{aligned}

Hedging with one unit of YY instead gives the error 5−2⋅3+4=35 - 2 \cdot 3 + 4 = 3, which is 2.752.75 plus E[d2]=(14)2⋅4=0.25E[d^2] = (\tfrac14)^2 \cdot 4 = 0.25 for d=14Yd = \tfrac14 Y, as the identity says.

Minimum-error hedge

Definition Let a target gain XX and hedge gains Y=(Y1,…,Ym)⊤Y = (Y_1, \dots, Y_m)^{\top} be centered with finite second moments, let ΣY\Sigma_Y be the covariance matrix of YY and let c=Cov⁡(Y,X)c = \operatorname{Cov}(Y, X) be the vector with entries Cov⁡(Yi,X)\operatorname{Cov}(Y_i, X). A minimum-error hedge is a holding vector hh that minimizes

J(h)=E[(X−h⊤Y)2]=Var⁡(X)−2h⊤c+h⊤ΣYh,\begin{aligned} J(h) &= E\bigl[(X - h^{\top} Y)^2\bigr] \\[0.4em] &= \operatorname{Var}(X) - 2h^{\top} c \\[0.4em] &\quad + h^{\top} \Sigma_Y h , \end{aligned}

where the second line comes from squaring the whole residual and taking expectations term by term. The gradient ∇J(h)=−2c+2ΣYh\nabla J(h) = -2c + 2\Sigma_Y h vanishes exactly at the solutions of the normal equations

ΣYh=c.\Sigma_Y h = c .

Since JJ is differentiable, every minimizer solves them. Conversely, the normal equations say Cov⁡(Yi,X−h⊤Y)=0\operatorname{Cov}(Y_i, X - h^{\top} Y) = 0 for every ii, so by the projection card every solution is a minimizer. For any solution the minimum residual variance is J(h)=Var⁡(X)−h⊤cJ(h) = \operatorname{Var}(X) - h^{\top} c. If ΣY\Sigma_Y is invertible, the hedge is unique and equals ΣY−1c\Sigma_Y^{-1} c. Centering removes the means, which are handled separately, and the result concerns this squared-error criterion only.

In plain words The best hedge in the squared-error sense leaves a residual that is uncorrelated with every hedge instrument, because any remaining correlation could be reduced by adjusting a holding. A positive residual variance means that the hedge is optimal for this criterion but does not replicate the target.

Example With the constructed inputs Var⁡(X)=5\operatorname{Var}(X) = 5, c=(3,1)c = (3, 1) and the covariance matrix with rows (4,2)(4, 2) and (2,4)(2, 4), the normal equations are 4h1+2h2=34h_1 + 2h_2 = 3 and 2h1+4h2=12h_1 + 4h_2 = 1. Doubling the second and subtracting the first gives 6h2=−16h_2 = -1, so h2=−16h_2 = -\tfrac16, and then 4h1=3+134h_1 = 3 + \tfrac13 gives h1=56h_1 = \tfrac56. The variance explained is

h⊤c=56⋅3−16⋅1=73,h^{\top} c = \tfrac56 \cdot 3 - \tfrac16 \cdot 1 = \tfrac73 ,

and the residual variance is 5−73=835 - \tfrac73 = \tfrac83. It is positive, so the optimal hedge leaves some risk. The hedge is short the second instrument although that instrument has positive covariance with the target, because the short position cancels part of the first instrument’s variance that the target does not share.

Pseudoinverse

Definition Let Σ=QΛQ⊤\Sigma = Q \Lambda Q^{\top} be a spectral decomposition of a real symmetric positive semidefinite matrix. Its Moore-Penrose pseudoinverse is

Σ+=QΛ+Q⊤,Λ+=diag⁡(λ1+,…,λd+),\begin{aligned} \Sigma^{+} &= Q \Lambda^{+} Q^{\top}, \\[0.4em] \Lambda^{+} &= \operatorname{diag}(\lambda_1^{+}, \dots, \lambda_d^{+}), \end{aligned}

where λ+=1/λ\lambda^{+} = 1/\lambda for λ>0\lambda > 0 and λ+=0\lambda^{+} = 0 for λ=0\lambda = 0. It equals Σ−1\Sigma^{-1} when Σ\Sigma is invertible. For a general matrix it is defined through the singular value decomposition, which is not derived here. If cc lies in the range of Σ\Sigma, then h+=Σ+ch^{+} = \Sigma^{+} c solves Σh=c\Sigma h = c, the solutions are exactly the vectors h++nh^{+} + n with Σn=0\Sigma n = 0, and h+h^{+} is the solution with the smallest Euclidean norm, because it lies in the range and so is orthogonal to every null vector nn. In a hedge with centered gains YY, a null vector nn of ΣY\Sigma_Y has Var⁡(n⊤Y)=n⊤ΣYn=0\operatorname{Var}(n^{\top} Y) = n^{\top} \Sigma_Y n = 0, so n⊤Y=0n^{\top} Y = 0 with probability 11. Hence all solutions give the same hedge payoff and the same residual variance, and n⊤c=Cov⁡(n⊤Y,X)=0n^{\top} c = \operatorname{Cov}(n^{\top} Y, X) = 0. The covariance vector of a genuine square-integrable target is therefore orthogonal to the null space, which for a symmetric matrix means that it lies in the range, so the normal equations always have a solution.

In plain words When two instruments are duplicates, only the total holding in them matters, and ordinary inversion fails because infinitely many splits give the same hedge. The pseudoinverse inverts the directions that carry variance, ignores the directions that carry none and picks the split with the smallest holdings. That choice of representation does not lower the residual variance. A small but nonzero eigenvalue is a different problem, because inverting it multiplies any estimation error along its direction by a large factor.

Example Let both hedge gains equal the same centered variable ZZ with variance 11, and let Cov⁡(Z,X)=2\operatorname{Cov}(Z, X) = 2, so every entry of ΣY\Sigma_Y is 11 and c=(2,2)c = (2, 2). The eigenvalues are 22, with unit eigenvector (1,1)/2(1, 1)/\sqrt{2}, and 00, with unit eigenvector (1,−1)/2(1, -1)/\sqrt{2}. Both normal equations reduce to h1+h2=2h_1 + h_2 = 2, and

ΣY+=14[1111],h+=ΣY+c=(1,1).\begin{gathered} \Sigma_Y^{+} = \frac14 \begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix}, \\[0.4em] h^{+} = \Sigma_Y^{+} c = (1, 1). \end{gathered}

The holdings (2,0)(2, 0) give the same payoff 2Z2Z with norm 22 instead of 2\sqrt{2}, and if Var⁡(X)=5\operatorname{Var}(X) = 5 both leave the residual variance 5−4=15 - 4 = 1. Now make the instruments nearly duplicates, with unit variances and correlation 0.990.99, so the eigenvalues are 1.991.99 and 0.010.01. For c=(2,2)c = (2, 2) the hedge is about (1.005,1.005)(1.005, 1.005). An estimation error that moves cc to (2.02,1.98)(2.02, 1.98) changes it to about (3.005,−0.995)(3.005, -0.995), because the error (0.02,−0.02)(0.02, -0.02) lies along the eigenvector with eigenvalue 0.010.01 and is multiplied by 100100. These numbers are constructed.

Check yourself

  1. Two assets have annual returns with variances 0.040.04 and 0.090.09 and covariance 0.010.01, in squared decimal units. Find the variance and the volatility of the portfolio with weights 0.60.6 and 0.40.4.
Show the answer

The portfolio variance is the quadratic form

w⊤Σw=0.36⋅0.04+0.16⋅0.09+2⋅0.6⋅0.4⋅0.01=0.0144+0.0144+0.0048=0.0336.\begin{aligned} w^{\top} \Sigma w &= 0.36 \cdot 0.04 + 0.16 \cdot 0.09 \\[0.4em] &\quad + 2 \cdot 0.6 \cdot 0.4 \cdot 0.01 \\[0.4em] &= 0.0144 + 0.0144 + 0.0048 \\[0.4em] &= 0.0336 . \end{aligned}

The volatility is 0.0336≈0.1833\sqrt{0.0336} \approx 0.1833 per year. Forgetting the factor 22 on the covariance term, which appears once for each order of the two assets, would give 0.03120.0312.

  1. A target gain XX has variance 1010. Two hedge gains have variances 22 and 22, covariance 11 with each other, and covariances 33 and 00 with XX, and all three are centered. A colleague drops the second instrument because it is uncorrelated with the target. Find the minimum-error hedge with both instruments and compare its residual variance with that of the best hedge using the first instrument alone.
Show the answer

The normal equations are 2h1+h2=32h_1 + h_2 = 3 and h1+2h2=0h_1 + 2h_2 = 0. The second gives h2=−h1/2h_2 = -h_1/2, and then 32h1=3\tfrac32 h_1 = 3, so h1=2h_1 = 2 and h2=−1h_2 = -1. The explained variance is h⊤c=2⋅3+(−1)⋅0=6h^{\top} c = 2 \cdot 3 + (-1) \cdot 0 = 6, and the residual variance is 10−6=410 - 6 = 4. As a check, the residual X−2Y1+Y2X - 2Y_1 + Y_2 has covariance 3−4+1=03 - 4 + 1 = 0 with Y1Y_1 and 0−2+2=00 - 2 + 2 = 0 with Y2Y_2.

With the first instrument alone the hedge is 3/23/2, the explained variance is 3⋅32=4.53 \cdot \tfrac32 = 4.5 and the residual variance is 5.55.5. Dropping the second instrument was a mistake. It is uncorrelated with the target but correlated with the first instrument, and the short position in it cancels part of the first instrument’s variance that the target does not share.

  1. Two hedge gains satisfy Y2=2Y1Y_2 = 2Y_1, where Y1Y_1 is centered with variance 11, and Cov⁡(Y1,X)=1.5\operatorname{Cov}(Y_1, X) = 1.5 and Var⁡(X)=4\operatorname{Var}(X) = 4. Write the normal equations, describe all solutions, and find the pseudoinverse solution and the residual variance. An estimate later reports Cov⁡(Y2,X)=3.2\operatorname{Cov}(Y_2, X) = 3.2. What does that tell you?
Show the answer

The covariance matrix has rows (1,2)(1, 2) and (2,4)(2, 4), and c=(1.5,3)c = (1.5, 3) because Cov⁡(Y2,X)=2⋅1.5\operatorname{Cov}(Y_2, X) = 2 \cdot 1.5. The normal equations h1+2h2=1.5h_1 + 2h_2 = 1.5 and 2h1+4h2=32h_1 + 4h_2 = 3 are the same equation, so the solutions are (1.5−2s,s)(1.5 - 2s, s) for every real ss. The matrix has eigenvalue 55 with unit eigenvector (1,2)/5(1, 2)/\sqrt{5} and eigenvalue 00 with unit eigenvector (2,−1)/5(2, -1)/\sqrt{5}, so

ΣY+=125[1224],h+=ΣY+c=(0.3,0.6).\begin{gathered} \Sigma_Y^{+} = \frac{1}{25} \begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}, \\[0.4em] h^{+} = \Sigma_Y^{+} c = (0.3, 0.6). \end{gathered}

Its squared norm is 0.450.45, smaller than the 2.252.25 of the solution (1.5,0)(1.5, 0). Every solution gives the payoff 1.5 Y11.5\,Y_1 and the residual variance 4−(0.3⋅1.5+0.6⋅3)=4−2.25=1.754 - (0.3 \cdot 1.5 + 0.6 \cdot 3) = 4 - 2.25 = 1.75.

Since Y2=2Y1Y_2 = 2Y_1 exactly, any genuine covariance satisfies Cov⁡(Y2,X)=2Cov⁡(Y1,X)=3\operatorname{Cov}(Y_2, X) = 2\operatorname{Cov}(Y_1, X) = 3. The reported 3.23.2 puts c=(1.5,3.2)c = (1.5, 3.2) outside the range of ΣY\Sigma_Y, and the equations h1+2h2=1.5h_1 + 2h_2 = 1.5 and 2h1+4h2=3.22h_1 + 4h_2 = 3.2 contradict each other. The inputs are inconsistent with the model. Applying ΣY+\Sigma_Y^{+} anyway returns the minimum-norm least-squares solution of an inconsistent system, which is not the covariance hedge derived above.

How this lesson connects