SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.5.1 Joint, marginal and conditional distributionsConcept · 30 min
      2. 5.5.2 Covariance, correlation and independenceConcept · 35 min
      3. 5.5.3 The multivariate normal distributionConcept · 35 min
      4. 5.5.4 Practice set: joint distributionsPractice set · 25 min
      5. 5.5.5 Case study: portfolio risk and conditional expectationCase study · 35 min

Level 5, Probability and statistics 5.5 Joint distributions Lesson 3 of 5

ConceptLesson 5.5.3 in Level 5, Probability and statistics. About 35 minutes.

The multivariate normal distribution

Built from independent standard normals

Start with independent standard normal variables Z1,…,ZnZ_1, \ldots, Z_n, collected in a random vector Z\mathbf{Z}. Their joint density is φ(z1)⋯φ(zn)\varphi(z_1)\cdots\varphi(z_n), the product of lesson 5.5.1. Now mix them with a matrix LL and shift them by a vector μ\boldsymbol{\mu}.

Rule: Multivariate normal

X=μ+LZX∼N(μ,Σ),Σ=LL⊤\begin{gathered} \mathbf{X} = \boldsymbol{\mu} + L\mathbf{Z} \\[4pt] \mathbf{X} \sim \mathcal{N}(\boldsymbol{\mu}, \Sigma), \quad \Sigma = LL^\top \end{gathered}

X\mathbf{X} is jointly normal, or multivariate normal, with mean vector μ\boldsymbol{\mu} and covariance matrix Σ\Sigma. Here LL is an n×nn \times n matrix with det⁡L≠0\det L \neq 0, and Z\mathbf{Z} holds independent standard normals.

Take μ=(1,3)\boldsymbol{\mu} = (1, 3) and L=(2012)L = \begin{pmatrix} 2 & 0 \\ 1 & 2 \end{pmatrix}, so that

X1=1+2Z1X2=3+Z1+2Z2\begin{gathered} X_1 = 1 + 2Z_1 \\ X_2 = 3 + Z_1 + 2Z_2 \end{gathered}

Each is normal on its own. X1X_1 is a linear change of Z1Z_1, so X1∼N(1,4)X_1 \sim \mathcal{N}(1, 4) (lesson 5.4.3). X2X_2 is 3 plus a sum of independent normals, so X2∼N(3,1+4)=N(3,5)X_2 \sim \mathcal{N}(3, 1 + 4) = \mathcal{N}(3, 5).

They share Z1Z_1, so they are linked. By the bilinearity of lesson 5.5.2, Cov⁡(X1,X2)=Cov⁡(2Z1, Z1+2Z2)=2Cov⁡(Z1,Z1)=2\operatorname{Cov}(X_1, X_2) = \operatorname{Cov}(2Z_1,\ Z_1 + 2Z_2) = 2\operatorname{Cov}(Z_1, Z_1) = 2. So

Σ=(4225)ρ=24⋅5=0.4472\begin{gathered} \Sigma = \begin{pmatrix} 4 & 2 \\ 2 & 5 \end{pmatrix} \\[6pt] \rho = \frac{2}{\sqrt{4 \cdot 5}} = 0.4472 \end{gathered}

Case study 3.7.4 simulated the three assets' returns in exactly this way, with the Cholesky factor of their covariance matrix as LL.

The covariance rule for random vectors

Two rules describe any linear change AX+bA\mathbf{X} + \mathbf{b} of a random vector, with AA a matrix and b\mathbf{b} a vector. The mean moves by linearity, entry by entry (lesson 5.3.2). The covariance matrix follows from bilinearity: entry (i,j)(i, j) of AΣA⊤A\Sigma A^\top is the covariance of entries ii and jj of AXA\mathbf{X}.

Rule: Linear change of a random vector

E[AX+b]=Aμ+bCov⁡(AX+b)=A Σ A⊤\begin{gathered} \mathbb{E}[A\mathbf{X} + \mathbf{b}] = A\boldsymbol{\mu} + \mathbf{b} \\[4pt] \operatorname{Cov}(A\mathbf{X} + \mathbf{b}) = A\,\Sigma\,A^\top \end{gathered}

Cov⁡(X)\operatorname{Cov}(\mathbf{X}) means the covariance matrix of X\mathbf{X}, here Σ\Sigma. The shift b\mathbf{b} changes the mean only. The rule holds for any random vector, normal or not.

Independent standard normals have mean 0\mathbf{0} and covariance matrix II, the identity. So μ+LZ\boldsymbol{\mu} + L\mathbf{Z} has mean μ\boldsymbol{\mu} and covariance matrix LIL⊤=LL⊤LIL^\top = LL^\top. Case study 3.7.4 found SX=LSZL⊤S_X = LS_ZL^\top for samples; this is the same rule for random variables, with SZ≈IS_Z \approx I replaced by II exactly.

For the example, LL⊤=(4225)LL^\top = \begin{pmatrix} 4 & 2 \\ 2 & 5 \end{pmatrix}, as found term by term above. For the three assets, case study 3.7.4's LL gives back case study 3.2.5's Σ\Sigma.

Only μ\boldsymbol{\mu} and Σ\Sigma matter: two matrices LL with the same LL⊤LL^\top give the same distribution. Given Σ\Sigma, the usual choice is its Cholesky factor (lesson 3.7.2); the symmetric square root of lesson 3.7.2 is another. Case study 5.5.5 uses the rule with a single row, A=w⊤A = \mathbf{w}^\top.

Try it

The first line checks LL⊤LL^\top, then 100,000 draws of Z\mathbf{Z} with a fixed seed become X\mathbf{X}. Z @ L.T turns each row z⊤\mathbf{z}^\top into (Lz)⊤(L\mathbf{z})^\top, as in case study 3.7.4.

In this run the sample means are 1.012 and 3.009. The sample covariance matrix has entries 3.976, 1.959 and 4.967, near 4, 2 and 5. The last lines check the symmetric square root.

⌘/Ctrl + Enter runs the cell

The density

Case study 4.7.5 found the density of μ+LZ\boldsymbol{\mu} + L\mathbf{Z} for two variables: φ(z1) φ(z2)det⁡L\frac{\varphi(z_1)\,\varphi(z_2)}{\det L}, with z=L−1(x−μ)\mathbf{z} = L^{-1}(\mathbf{x} - \boldsymbol{\mu}). Two facts rewrite it with Σ\Sigma alone.

  • The exponent. φ(z1)φ(z2)=12πe−z⊤z/2\varphi(z_1)\varphi(z_2) = \frac{1}{2\pi}e^{-\mathbf{z}^\top\mathbf{z}/2}. Since Σ−1=(LL⊤)−1=(L⊤)−1L−1\Sigma^{-1} = (LL^\top)^{-1} = (L^\top)^{-1}L^{-1} (lesson 3.2.3), z⊤z=(x−μ)⊤Σ−1(x−μ)\mathbf{z}^\top\mathbf{z} = (\mathbf{x} - \boldsymbol{\mu})^\top\Sigma^{-1}(\mathbf{x} - \boldsymbol{\mu}).
  • The constant. det⁡Σ=(det⁡L)2\det \Sigma = (\det L)^2 (lesson 3.7.2), so det⁡L=det⁡Σ\det L = \sqrt{\det \Sigma}.

Rule: Multivariate normal density

f(x)=e−Q/2(2π)n/2det⁡ΣQ=(x−μ)⊤Σ−1(x−μ)\begin{gathered} f(\mathbf{x}) = \frac{e^{-Q/2}}{(2\pi)^{n/2}\sqrt{\det \Sigma}} \\[6pt] Q = (\mathbf{x} - \boldsymbol{\mu})^\top\Sigma^{-1}(\mathbf{x} - \boldsymbol{\mu}) \end{gathered}

QQ measures how far x\mathbf{x} is from μ\boldsymbol{\mu} in units set by Σ\Sigma. With n=1n = 1 and Σ=σ2\Sigma = \sigma^2, Q=(x−μ)2σ2Q = \frac{(x - \mu)^2}{\sigma^2} and this is lesson 5.4.3's normal density.

For two variables, write u=x−μXσXu = \frac{x - \mu_X}{\sigma_X} and v=y−μYσYv = \frac{y - \mu_Y}{\sigma_Y} for the standardised values. Then det⁡Σ=σX2σY2(1−ρ2)\det \Sigma = \sigma_X^2\sigma_Y^2(1 - \rho^2), and

f(x,y)=e−Q/22πσXσY1−ρ2Q=u2−2ρuv+v21−ρ2\begin{gathered} f(x, y) = \frac{e^{-Q/2}}{2\pi\sigma_X\sigma_Y\sqrt{1 - \rho^2}} \\[6pt] Q = \frac{u^2 - 2\rho uv + v^2}{1 - \rho^2} \end{gathered}

The example. det⁡Σ=4⋅5−2⋅2=16=(det⁡L)2\det \Sigma = 4 \cdot 5 - 2 \cdot 2 = 16 = (\det L)^2, and Σ−1=116(5−2−24)\Sigma^{-1} = \frac{1}{16}\begin{pmatrix} 5 & -2 \\ -2 & 4 \end{pmatrix}. At x=(3,3)\mathbf{x} = (3, 3), x−μ=(2,0)\mathbf{x} - \boldsymbol{\mu} = (2, 0) and Q=4⋅516=1.25Q = \frac{4 \cdot 5}{16} = 1.25. The other route gives z=(1,−0.5)\mathbf{z} = (1, -0.5), and z⊤z=1.25\mathbf{z}^\top\mathbf{z} = 1.25 too.

So f(3,3)=e−0.6258π=0.021297f(3, 3) = \frac{e^{-0.625}}{8\pi} = 0.021297. The peak, at μ\boldsymbol{\mu}, is 18π=0.039789\frac{1}{8\pi} = 0.039789.

Case study 4.7.5's returns. For A and B, det⁡Σ=0.020605\sqrt{\det \Sigma} = 0.020605, the det⁡L\det L of that case study, and the peak 12πdet⁡Σ\frac{1}{2\pi\sqrt{\det \Sigma}} is its 7.7241. At (0,−0.1)(0, -0.1) the density is 4.583039, the value of case study 4.7.5's formula there.

Try it

density is the rule: np.linalg.solve finds Σ−1(x−μ)\Sigma^{-1}(\mathbf{x} - \boldsymbol{\mu}) without inverting Σ\Sigma (lesson 3.3.1). It agrees with case study 4.7.5's φ(z1)φ(z2)det⁡L\frac{\varphi(z_1)\varphi(z_2)}{\det L} and with SciPy's multivariate_normal(...).pdf.

The last lines repeat the check for case study 4.7.5's assets A and B.

⌘/Ctrl + Enter runs the cell

Level curves are ellipses

The density depends on x\mathbf{x} only through QQ, so it is constant where Q=cQ = c. Σ−1\Sigma^{-1} is positive definite, so these level curves are ellipses centred at μ\boldsymbol{\mu} (lesson 3.7.1).

Their axes lie along the eigenvectors of Σ\Sigma, which are also those of Σ−1\Sigma^{-1}. An eigenvalue λi\lambda_i of Σ\Sigma is 1λi\frac{1}{\lambda_i} for Σ−1\Sigma^{-1}, so lesson 3.7.1's semi-axis rule gives c λi\sqrt{c\,\lambda_i}.

Rule: Ellipses of the normal

Q=c: semi-axes c λin=2: P(Q≤c)=1−e−c/2\begin{gathered} Q = c: \text{ semi-axes } \sqrt{c\,\lambda_i} \\[4pt] n = 2:\ P(Q \le c) = 1 - e^{-c/2} \end{gathered}

λi\lambda_i are the eigenvalues of Σ\Sigma, and the axes point along its eigenvectors. With two variables, the ellipse Q=cQ = c holds the probability 1−e−c/21 - e^{-c/2}, whatever μ\boldsymbol{\mu} and Σ\Sigma are.

The probability comes from case study 4.7.5. There z\mathbf{z} landed within distance rr of the origin with probability 1−e−r2/21 - e^{-r^2/2}, and Q=z⊤zQ = \mathbf{z}^\top\mathbf{z} is that distance squared.

For the example, Σ\Sigma has eigenvalues 9∓172\frac{9 \mp \sqrt{17}}{2}: 2.4384 along (0.7882,−0.6154)(0.7882, -0.6154) and 6.5616 along (0.6154,0.7882)(0.6154, 0.7882). The long axis rises at 52.02° to the xx-axis. The ellipse Q=1Q = 1 has semi-axes 1.5616 and 2.5616, and Q=4Q = 4 twice those.

ellipseQ=1Q = 1Q=4Q = 4Q=9Q = 9
probability inside, 1−e−c/21 - e^{-c/2}0.39350.86470.9889
share of 100,000 draws0.39420.86460.9891

Draws of X=μ+LZ\mathbf{X} = \boldsymbol{\mu} + L\mathbf{Z} and the ellipses Q=1Q = 1, 4 and 9 of its density. The axes lie along the eigenvectors of Σ\Sigma, with semi-axes cλi\sqrt{c\lambda_i}; correlation tilts them away from the coordinate axes.

With ρ=0\rho = 0, Σ\Sigma is diagonal and the axes are the coordinate axes. The ellipses of case study 4.7.5's figure tilted only once the correlation was 0.3.

Try it

eigh (lesson 3.6.3) gives the eigenvalues and eigenvectors of Σ\Sigma; the cell makes each eigenvector's first entry positive. Then the semi-axes for c=1c = 1, 4 and 9.

For each draw, the cell computes QQ and counts the share with Q≤cQ \le c, against 1−e−c/21 - e^{-c/2}.

⌘/Ctrl + Enter runs the cell

Linear combinations are normal

Any combination a⊤X=a1X1+⋯+anXn\mathbf{a}^\top\mathbf{X} = a_1X_1 + \cdots + a_nX_n of jointly normal variables is a⊤μ+(a⊤L)Z\mathbf{a}^\top\boldsymbol{\mu} + (\mathbf{a}^\top L)\mathbf{Z}. That is a constant plus a combination of independent normals, so it is normal (lesson 5.4.3). Its mean and variance come from the rule above with the single row A=a⊤A = \mathbf{a}^\top.

Rule: Combinations of jointly normal variables

a⊤X∼N(a⊤μ, a⊤Σ a)AX+b∼N(Aμ+b, AΣA⊤)\begin{gathered} \mathbf{a}^\top\mathbf{X} \sim \mathcal{N}\big(\mathbf{a}^\top\boldsymbol{\mu},\ \mathbf{a}^\top\Sigma\,\mathbf{a}\big) \\[4pt] A\mathbf{X} + \mathbf{b} \sim \mathcal{N}\big(A\boldsymbol{\mu} + \mathbf{b},\ A\Sigma A^\top\big) \end{gathered}

Sums of normal variables are normal when they are independent, or more generally jointly normal. Several combinations at once, AX+bA\mathbf{X} + \mathbf{b}, are jointly normal too.

In the example, X1+X2=4+3Z1+2Z2X_1 + X_2 = 4 + 3Z_1 + 2Z_2, so X1+X2∼N(4,13)X_1 + X_2 \sim \mathcal{N}(4, 13). Lesson 5.5.2's rule agrees: 4+5+2⋅2=134 + 5 + 2 \cdot 2 = 13. Likewise X1−X2∼N(−2,4+5−4)=N(−2,5)X_1 - X_2 \sim \mathcal{N}(-2, 4 + 5 - 4) = \mathcal{N}(-2, 5).

A probability then needs only lesson 5.4.3. P(X1+X2>10)=1−N(10−413)=1−N(1.6641)=0.04805P(X_1 + X_2 > 10) = 1 - N\big(\frac{10 - 4}{\sqrt{13}}\big) = 1 - N(1.6641) = 0.04805, with NN the standard normal distribution function. The seeded draws give 0.04805 too.

Case study 4.7.5 used this rule before it was stated. Half in A and half in B is normal, with mean 7% and volatility 12.2229%. So it loses more than 10% with probability 0.082139, the same as that case study's double integral.

Try it

a @ mu and a @ Sigma @ a give the mean and variance of a⊤X\mathbf{a}^\top\mathbf{X}. The cell does X1+X2X_1 + X_2 and X1−X2X_1 - X_2, then the probability, exact and from the same 100,000 seeded draws.

⌘/Ctrl + Enter runs the cell

Uncorrelated jointly normal variables are independent

When every correlation is 0, Σ\Sigma is diagonal, with the variances σi2\sigma_i^2 on it. Then Q=∑i(xi−μi)2σi2Q = \sum_i \frac{(x_i - \mu_i)^2}{\sigma_i^2} and det⁡Σ=σ12⋯σn2\det \Sigma = \sigma_1^2 \cdots \sigma_n^2. The exponential of a sum is a product, so the density splits into nn one-variable normal densities: by lesson 5.5.1, the variables are independent.

For example, with μ=(1,0)\boldsymbol{\mu} = (1, 0) and Σ\Sigma diagonal with entries 4 and 9, the density at (2,−1)(2, -1) is 0.022144. That is the N(1,4)\mathcal{N}(1, 4) density at 2 times the N(0,9)\mathcal{N}(0, 9) density at −1-1.

Normal one at a time is not enough. Let ZZ be standard normal, and SS an independent fair coin flip, 1 or −1-1. Set Y=SZY = SZ.

  • YY is standard normal, since flipping the sign of a symmetric variable at random changes nothing.
  • Cov⁡(Z,Y)=E[SZ2]=E[S] E[Z2]=0\operatorname{Cov}(Z, Y) = \mathbb{E}[SZ^2] = \mathbb{E}[S]\,\mathbb{E}[Z^2] = 0: uncorrelated.
  • Yet ∣Y∣=∣Z∣\lvert Y \rvert = \lvert Z \rvert always, so they are dependent.

The pair (Z,Y)(Z, Y) is not jointly normal. Whenever S=−1S = -1, Z+Y=0Z + Y = 0, so P(Z+Y=0)=12P(Z + Y = 0) = \frac{1}{2}, and no normal variable takes one value with probability 12\frac{1}{2}.

Two pairs with standard normal coordinates and zero correlation. Only the first is jointly normal, and only there are the coordinates independent.

Rule: Zero correlation and independence

jointly normal and Σ diagonal  ⟹  independent\begin{gathered} \text{jointly normal and } \Sigma \text{ diagonal} \\ \implies \text{independent} \end{gathered}

For jointly normal variables, uncorrelated and independent mean the same. Normal one at a time is not enough: ZZ and SZSZ are both normal and uncorrelated, but dependent.

Try it

The first line compares the diagonal density with the product of two normal densities; norm.pdf(x, mean, sd) takes the standard deviation.

Then 100,000 draws of ZZ and SS with a fixed seed. In this run YY has mean 0.0 and standard deviation 1.003. Of its draws, 0.6812 lie within 1 of 0, against 0.6827 for a normal.

The correlation of ZZ and YY is 0.0048, Z+YZ + Y is exactly 0 in 0.5007 of the draws, and ∣Z∣\lvert Z \rvert and ∣Y∣\lvert Y \rvert have correlation 1.

⌘/Ctrl + Enter runs the cell

In Python

SciPy's multivariate_normal(mean, cov) gives the density with .pdf and draws with .rvs(size, random_state=rng). NumPy's rng.multivariate_normal(mean, cov, size, method="cholesky") draws too; case study 3.2.5 used it. Both take the covariance matrix, not the volatilities or the correlation matrix.

SciPy's .cdf finds probabilities by a randomised numerical method, so its last digits can change from run to run. For the probability of a region, use dblquad (case study 4.7.5) or a seeded simulation.

The covariance matrix must be valid: symmetric and positive semidefinite (case study 3.7.4). Repair a matrix that is not before drawing from it.

Try it

The cell draws 100,000 years of the three assets of case study 3.2.5 with rvs and a fixed seed.

In this run the sample means are 0.0597, 0.0788 and 0.1084, the volatilities 0.1203, 0.1804 and 0.2496, and the correlations 0.300, 0.100 and 0.499.

⌘/Ctrl + Enter runs the cell

Case study 5.5.5 uses this distribution to ask what one asset's return says about another's.

Common mistakes

  1. Normal one at a time is not jointly normal. For ZZ and SZSZ, zero correlation does not give independence, and Z+SZZ + SZ is not normal.
  2. The density uses Σ−1\Sigma^{-1} and det⁡Σ\sqrt{\det \Sigma}. In two variables the constant is 2πdet⁡Σ2\pi\sqrt{\det \Sigma}, here 8π8\pi, not 2πdet⁡Σ2\pi \det \Sigma.
  3. Combinations need the covariances. Var⁡(X1+X2)=13\operatorname{Var}(X_1 + X_2) = 13, not 4+5=94 + 5 = 9.
  4. cov means the covariance matrix. Passing volatilities, standard deviations or the correlation matrix gives the wrong distribution, often without an error.
  5. The ellipses tilt. Their axes follow the eigenvectors of Σ\Sigma, not the coordinate axes, unless ρ=0\rho = 0.
  6. Check Σ\Sigma first. A matrix that is not positive semidefinite is not a covariance matrix (case study 3.7.4).

The multivariate normal distribution

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • X=μ+LZ\mathbf{X} = \boldsymbol{\mu} + L\mathbf{Z}, with Z\mathbf{Z} independent standard normals, is jointly normal: X∼N(μ,Σ)\mathbf{X} \sim \mathcal{N}(\boldsymbol{\mu}, \Sigma) with Σ=LL⊤\Sigma = LL^\top. Only μ\boldsymbol{\mu} and Σ\Sigma matter.
  • For any random vector, E[AX+b]=Aμ+b\mathbb{E}[A\mathbf{X} + \mathbf{b}] = A\boldsymbol{\mu} + \mathbf{b} and Cov⁡(AX+b)=AΣA⊤\operatorname{Cov}(A\mathbf{X} + \mathbf{b}) = A\Sigma A^\top.
  • Density: f(x)=e−Q/2(2π)n/2det⁡Σf(\mathbf{x}) = \frac{e^{-Q/2}}{(2\pi)^{n/2}\sqrt{\det \Sigma}} with Q=(x−μ)⊤Σ−1(x−μ)Q = (\mathbf{x} - \boldsymbol{\mu})^\top\Sigma^{-1}(\mathbf{x} - \boldsymbol{\mu}); for two variables, det⁡Σ=σXσY1−ρ2=det⁡L\sqrt{\det \Sigma} = \sigma_X\sigma_Y\sqrt{1 - \rho^2} = \det L.
  • Level curves Q=cQ = c are ellipses along the eigenvectors of Σ\Sigma, semi-axes cλi\sqrt{c\lambda_i}; with two variables they hold 1−e−c/21 - e^{-c/2}.
  • Every combination a⊤X\mathbf{a}^\top\mathbf{X} is N(a⊤μ,a⊤Σa)\mathcal{N}(\mathbf{a}^\top\boldsymbol{\mu}, \mathbf{a}^\top\Sigma\mathbf{a}).
  • Jointly normal and uncorrelated means independent. Normal one at a time is not enough: ZZ and SZSZ.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.