Start with independent standard normal variables Z1,…,Zn, collected in a random vector Z. Their joint density is φ(z1)⋯φ(zn), the product of lesson 5.5.1. Now mix them with a matrix L and shift them by a vector μ.
Rule: Multivariate normal
X=μ+LZX∼N(μ,Σ),Σ=LL⊤
X is jointly normal, or multivariate normal, with mean vector μ and covariance matrix Σ. Here L is an n×n matrix with detL=0, and Z holds independent standard normals.
Take μ=(1,3) and L=(2102), so that
X1=1+2Z1X2=3+Z1+2Z2
Each is normal on its own. X1 is a linear change of Z1, so X1∼N(1,4) (lesson 5.4.3). X2 is 3 plus a sum of independent normals, so X2∼N(3,1+4)=N(3,5).
They share Z1, so they are linked. By the bilinearity of lesson 5.5.2, Cov(X1,X2)=Cov(2Z1,Z1+2Z2)=2Cov(Z1,Z1)=2. So
Σ=(4225)ρ=4⋅52=0.4472
Case study 3.7.4 simulated the three assets' returns in exactly this way, with the Cholesky factor of their covariance matrix as L.
The covariance rule for random vectors
Two rules describe any linear change AX+b of a random vector, with A a matrix and b a vector. The mean moves by linearity, entry by entry (lesson 5.3.2). The covariance matrix follows from bilinearity: entry (i,j) of AΣA⊤ is the covariance of entries i and j of AX.
Rule: Linear change of a random vector
E[AX+b]=Aμ+bCov(AX+b)=AΣA⊤
Cov(X) means the covariance matrix of X, here Σ. The shift b changes the mean only. The rule holds for any random vector, normal or not.
Independent standard normals have mean 0 and covariance matrix I, the identity. So μ+LZ has mean μ and covariance matrix LIL⊤=LL⊤. Case study 3.7.4 found SX=LSZL⊤ for samples; this is the same rule for random variables, with SZ≈I replaced by I exactly.
For the example, LL⊤=(4225), as found term by term above. For the three assets, case study 3.7.4's L gives back case study 3.2.5's Σ.
Only μ and Σ matter: two matrices L with the same LL⊤ give the same distribution. Given Σ, 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⊤.
Try it
The first line checks LL⊤, then 100,000 draws of Z with a fixed seed become X. Z @ L.T turns each row z⊤ into (Lz)⊤, 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 for two variables: detLφ(z1)φ(z2), with z=L−1(x−μ). Two facts rewrite it with Σ alone.
The exponent.φ(z1)φ(z2)=2π1e−z⊤z/2. Since Σ−1=(LL⊤)−1=(L⊤)−1L−1 (lesson 3.2.3), z⊤z=(x−μ)⊤Σ−1(x−μ).
The constant.detΣ=(detL)2 (lesson 3.7.2), so detL=detΣ.
Rule: Multivariate normal density
f(x)=(2π)n/2detΣe−Q/2Q=(x−μ)⊤Σ−1(x−μ)
Q measures how far x is from μ in units set by Σ. With n=1 and Σ=σ2, Q=σ2(x−μ)2 and this is lesson 5.4.3's normal density.
For two variables, write u=σXx−μX and v=σYy−μY for the standardised values. Then detΣ=σX2σY2(1−ρ2), and
f(x,y)=2πσXσY1−ρ2e−Q/2Q=1−ρ2u2−2ρuv+v2
The example.detΣ=4⋅5−2⋅2=16=(detL)2, and Σ−1=161(5−2−24). At x=(3,3), x−μ=(2,0) and Q=164⋅5=1.25. The other route gives z=(1,−0.5), and z⊤z=1.25 too.
So f(3,3)=8πe−0.625=0.021297. The peak, at μ, is 8π1=0.039789.
Case study 4.7.5's returns. For A and B, detΣ=0.020605, the detL of that case study, and the peak 2πdetΣ1 is its 7.7241. At (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−μ) without inverting Σ (lesson 3.3.1). It agrees with case study 4.7.5's detLφ(z1)φ(z2) 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 only through Q, so it is constant where Q=c. Σ−1 is positive definite, so these level curves are ellipses centred at μ (lesson 3.7.1).
Their axes lie along the eigenvectors of Σ, which are also those of Σ−1. An eigenvalue λi of Σ is λi1 for Σ−1, so lesson 3.7.1's semi-axis rule gives cλi.
Rule: Ellipses of the normal
Q=c: semi-axes cλin=2:P(Q≤c)=1−e−c/2
λi are the eigenvalues of Σ, and the axes point along its eigenvectors. With two variables, the ellipse Q=c holds the probability 1−e−c/2, whatever μ and Σ are.
The probability comes from case study 4.7.5. There z landed within distance r of the origin with probability 1−e−r2/2, and Q=z⊤z is that distance squared.
For the example, Σ has eigenvalues 29∓17: 2.4384 along (0.7882,−0.6154) and 6.5616 along (0.6154,0.7882). The long axis rises at 52.02° to the x-axis. The ellipse Q=1 has semi-axes 1.5616 and 2.5616, and Q=4 twice those.
ellipse
Q=1
Q=4
Q=9
probability inside, 1−e−c/2
0.3935
0.8647
0.9889
share of 100,000 draws
0.3942
0.8646
0.9891
Draws of X=μ+LZ and the ellipses Q=1, 4 and 9 of its density. The axes lie along the eigenvectors of Σ, with semi-axes cλi; correlation tilts them away from the coordinate axes.
With ρ=0, Σ 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 Σ; the cell makes each eigenvector's first entry positive. Then the semi-axes for c=1, 4 and 9.
For each draw, the cell computes Q and counts the share with Q≤c, against 1−e−c/2.
⌘/Ctrl + Enter runs the cell
Linear combinations are normal
Any combination a⊤X=a1X1+⋯+anXn of jointly normal variables is a⊤μ+(a⊤L)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⊤.
Rule: Combinations of jointly normal variables
a⊤X∼N(a⊤μ,a⊤Σa)AX+b∼N(Aμ+b,AΣA⊤)
Sums of normal variables are normal when they are independent, or more generally jointly normal. Several combinations at once, AX+b, are jointly normal too.
In the example, X1+X2=4+3Z1+2Z2, so X1+X2∼N(4,13). Lesson 5.5.2's rule agrees: 4+5+2⋅2=13. Likewise X1−X2∼N(−2,4+5−4)=N(−2,5).
A probability then needs only lesson 5.4.3. P(X1+X2>10)=1−N(1310−4)=1−N(1.6641)=0.04805, with N 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. The cell does X1+X2 and X1−X2, 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, Σ is diagonal, with the variances σi2 on it. Then Q=∑iσi2(xi−μi)2 and detΣ=σ12⋯σn2. The exponential of a sum is a product, so the density splits into n one-variable normal densities: by lesson 5.5.1, the variables are independent.
For example, with μ=(1,0) and Σ diagonal with entries 4 and 9, the density at (2,−1) is 0.022144. That is the N(1,4) density at 2 times the N(0,9) density at −1.
Normal one at a time is not enough. Let Z be standard normal, and S an independent fair coin flip, 1 or −1. Set Y=SZ.
Y 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: uncorrelated.
Yet ∣Y∣=∣Z∣ always, so they are dependent.
The pair (Z,Y) is not jointly normal. Whenever S=−1, Z+Y=0, so P(Z+Y=0)=21, and no normal variable takes one value with probability 21.
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
For jointly normal variables, uncorrelated and independent mean the same. Normal one at a time is not enough: Z and SZ 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 Z and S with a fixed seed. In this run Y 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 Z and Y is 0.0048, Z+Y is exactly 0 in 0.5007 of the draws, and ∣Z∣ and ∣Y∣ 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
Normal one at a time is not jointly normal. For Z and SZ, zero correlation does not give independence, and Z+SZ is not normal.
The density uses Σ−1 and detΣ. In two variables the constant is 2πdetΣ, here 8π, not 2πdetΣ.
Combinations need the covariances.Var(X1+X2)=13, not 4+5=9.
cov means the covariance matrix. Passing volatilities, standard deviations or the correlation matrix gives the wrong distribution, often without an error.
The ellipses tilt. Their axes follow the eigenvectors of Σ, not the coordinate axes, unless ρ=0.
Check Σ 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.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
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, with Z independent standard normals, is jointly normal: X∼N(μ,Σ) with Σ=LL⊤. Only μ and Σ matter.
For any random vector, E[AX+b]=Aμ+b and Cov(AX+b)=AΣA⊤.
Density: f(x)=(2π)n/2detΣe−Q/2 with Q=(x−μ)⊤Σ−1(x−μ); for two variables, detΣ=σXσY1−ρ2=detL.
Level curves Q=c are ellipses along the eigenvectors of Σ, semi-axes cλi; with two variables they hold 1−e−c/2.
Every combination a⊤X is N(a⊤μ,a⊤Σa).
Jointly normal and uncorrelated means independent. Normal one at a time is not enough: Z and SZ.