SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.6.1 Functions of random variablesConcept · 35 min
      2. 5.6.2 Moment generating and characteristic functionsConcept · 30 min
      3. 5.6.3 Sums of independent random variablesConcept · 25 min
      4. 5.6.4 Practice set: transformationsPractice set · 20 min
      5. 5.6.5 Case study: the lognormal from the normalCase study · 30 min

Level 5, Probability and statistics 5.6 Transformations and generating functions Lesson 3 of 5

ConceptLesson 5.6.3 in Level 5, Probability and statistics. About 25 minutes.

Sums of independent random variables

Two dice, by counting

Roll two fair dice, XX and YY, independently, and let S=X+YS = X + Y. Each of the 36 pairs has probability 16⋅16=136\frac{1}{6} \cdot \frac{1}{6} = \frac{1}{36}, by independence (lesson 5.5.1). So P(S=s)P(S = s) is the number of pairs that add up to ss, divided by 36.

sum ss234567
pairs123456

From 8 to 12 the counts fall back: 5, 4, 3, 2, 1. So P(S=7)=636=16P(S = 7) = \frac{6}{36} = \frac{1}{6}, P(S=4)=336=112P(S = 4) = \frac{3}{36} = \frac{1}{12}, and P(S≥10)=3+2+136=16P(S \ge 10) = \frac{3 + 2 + 1}{36} = \frac{1}{6}.

Each diagonal of the grid collects the pairs with one sum. Their counts, 1 to 6 and back to 1, make the pmf of SS a triangle.

The same table by convolution

To get S=sS = s, the first die shows some xx and the second must show s−xs - x. Multiply their probabilities, by independence, and add over every xx. For s=4s = 4 the splits are 1+31 + 3, 2+22 + 2 and 3+13 + 1, so P(S=4)=3⋅136P(S = 4) = 3 \cdot \frac{1}{36}.

Rule: Convolution

pS(s)=∑xpX(x) pY(s−x)fS(s)=∫−∞∞fX(x) fY(s−x) dx\begin{gathered} p_S(s) = \sum_x p_X(x)\,p_Y(s - x) \\[4pt] f_S(s) = \int_{-\infty}^{\infty} f_X(x)\,f_Y(s - x)\,dx \end{gathered}

For independent XX and YY: add the probability of every way to split ss into xx and s−xs - x. With densities, the sum becomes an integral. The operation is called convolution.

Try it

The loop counts the 36 pairs by their sum. np.convolve computes the convolution of the two pmfs; times 36 it gives the same counts.

Then 100,000 seeded pairs of rolls: the shares of 7 and of 4 come out near 16≈0.1667\frac{1}{6} \approx 0.1667 and 112≈0.0833\frac{1}{12} \approx 0.0833, in one run.

⌘/Ctrl + Enter runs the cell

The MGF of a sum is the product

Convolution gets slow for long sums and needs an integral for densities. The MGF of lesson 5.6.2 turns it into a multiplication. Since et(X+Y)=etXetYe^{t(X + Y)} = e^{tX}e^{tY}, the question is the mean of a product.

With XX and YY independent, E[g(X) h(Y)]=E[g(X)] E[h(Y)]\mathbb{E}[g(X)\,h(Y)] = \mathbb{E}[g(X)]\,\mathbb{E}[h(Y)] (lesson 5.5.2). The joint pmf is the product pX(x) pY(y)p_X(x)\,p_Y(y) (lesson 5.5.1), so the double sum splits into a product of two sums.

Rule: MGF of an independent sum

MX+Y(t)=MX(t) MY(t)ψX+Y(t)=ψX(t) ψY(t)\begin{gathered} M_{X + Y}(t) = M_X(t)\,M_Y(t) \\[4pt] \psi_{X + Y}(t) = \psi_X(t)\,\psi_Y(t) \end{gathered}

For independent XX and YY, and likewise for more terms: nn independent copies of XX have MGF MX(t)nM_X(t)^n. The characteristic functions multiply in the same way.

For two dice, MS(t)=(et+⋯+e6t6)2M_S(t) = \left(\frac{e^t + \cdots + e^{6t}}{6}\right)^2. Write uu for ete^t and multiply out:

(u+u2+⋯+u66)2=u2+2u3+3u4+⋯+6u7+⋯+u1236\begin{gathered} \left(\frac{u + u^2 + \cdots + u^6}{6}\right)^2 \\[4pt] = \frac{u^2 + 2u^3 + 3u^4 + \cdots + 6u^7 + \cdots + u^{12}}{36} \end{gathered}

The coefficient of us=estu^s = e^{st} is P(S=s)P(S = s). Multiplying the two polynomials collects the same splits as the convolution.

Try it

The first line checks the rule at t=0.3t = 0.3: the die's MGF squared against the MGF of the sum, built from the counts.

SymPy then multiplies out the polynomial, with u standing for ete^t. Its coefficients, times 36, are the counts.

⌘/Ctrl + Enter runs the cell

Sums that stay in their family

Multiply two MGFs, recognise the product, and the uniqueness rule of lesson 5.6.2 names the distribution of the sum.

Bernoullis make a binomial. A coin that shows 1 with probability pp has M(t)=1−p+petM(t) = 1 - p + pe^t (lesson 5.6.2). The number of 1s in nn independent tosses has M(t)=(1−p+pet)nM(t) = (1 - p + pe^t)^n. Multiplying out gives the binomial probabilities of lesson 5.2.2: with n=3n = 3 and p=0.3p = 0.3, (0.7+0.3u)3=0.343+0.441u+0.189u2+0.027u3(0.7 + 0.3u)^3 = 0.343 + 0.441u + 0.189u^2 + 0.027u^3.

Poissons make a Poisson. For a Poisson count with rate λ\lambda (lesson 5.2.3), the series for exe^x (lesson 2.7.2) sums the MGF:

M(t)=∑k=0∞etk e−λλkk!=e−λ∑k=0∞(λet)kk!=e−λeλet=eλ(et−1)\begin{aligned} M(t) &= \sum_{k=0}^{\infty} e^{tk}\,\frac{e^{-\lambda}\lambda^k}{k!} = e^{-\lambda}\sum_{k=0}^{\infty} \frac{(\lambda e^t)^k}{k!} \\ &= e^{-\lambda}e^{\lambda e^t} = e^{\lambda(e^t - 1)} \end{aligned}

Two independent counts with rates λ1\lambda_1 and λ2\lambda_2 give eλ1(et−1)eλ2(et−1)=e(λ1+λ2)(et−1)e^{\lambda_1(e^t - 1)}e^{\lambda_2(e^t - 1)} = e^{(\lambda_1 + \lambda_2)(e^t - 1)}: a Poisson with rate λ1+λ2\lambda_1 + \lambda_2. With rates 1 and 2, P(S=3)=e−3 333!≈0.224042P(S = 3) = \frac{e^{-3}\,3^3}{3!} \approx 0.224042, and convolution agrees.

Try it

The first line sums the Poisson MGF with λ=2\lambda = 2 at t=0.5t = 0.5 term by term, against eλ(et−1)e^{\lambda(e^t - 1)}.

Then the convolution of the Poisson pmfs with rates 1 and 2, against the rate-3 pmf, for counts 0 to 5. The binomial line compares (0.7+0.3u)3(0.7 + 0.3u)^3 with binom.pmf; the last line is 100,000 seeded sums of two Poisson counts.

⌘/Ctrl + Enter runs the cell

Sums of independent normals

Lesson 5.4.3 stated that a sum of independent normals is normal; the MGFs show why. Multiply eμ1t+σ12t2/2e^{\mu_1 t + \sigma_1^2 t^2/2} by eμ2t+σ22t2/2e^{\mu_2 t + \sigma_2^2 t^2/2} and the exponents add:

MX+Y(t)=e(μ1+μ2)t+(σ12+σ22)t2/2M_{X + Y}(t) = e^{(\mu_1 + \mu_2)t + (\sigma_1^2 + \sigma_2^2)t^2/2}

That is the MGF of a normal with mean μ1+μ2\mu_1 + \mu_2 and variance σ12+σ22\sigma_1^2 + \sigma_2^2.

Rule: Sums of independent normals

X∼N(μ1,σ12),  Y∼N(μ2,σ22)X+Y∼N(μ1+μ2, σ12+σ22)\begin{gathered} X \sim \mathcal{N}(\mu_1, \sigma_1^2),\; Y \sim \mathcal{N}(\mu_2, \sigma_2^2) \\[4pt] X + Y \sim \mathcal{N}(\mu_1 + \mu_2,\ \sigma_1^2 + \sigma_2^2) \end{gathered}

For independent XX and YY. Means add and variances add; standard deviations do not. More generally aX+bY∼N(aμ1+bμ2, a2σ12+b2σ22)aX + bY \sim \mathcal{N}(a\mu_1 + b\mu_2,\ a^2\sigma_1^2 + b^2\sigma_2^2).

An example. Take X∼N(1,4)X \sim \mathcal{N}(1, 4) and Y∼N(2,9)Y \sim \mathcal{N}(2, 9), independent. Then X+Y∼N(3,13)X + Y \sim \mathcal{N}(3, 13), with standard deviation 13≈3.605551\sqrt{13} \approx 3.605551, not 2+3=52 + 3 = 5. So P(X+Y>5)=1−N ⁣(5−313)≈0.28955P(X + Y > 5) = 1 - N\!\left(\frac{5 - 3}{\sqrt{13}}\right) \approx 0.28955; with the wrong 5 you would get 0.344578.

Differences. X−YX - Y is X+(−1)YX + (-1)Y, so its variance is 4+(−1)2⋅9=134 + (-1)^2 \cdot 9 = 13 again: variances add for differences too (lesson 5.5.2). Its mean is 1−2=−11 - 2 = -1.

Many terms. nn independent copies of N(μ,σ2)\mathcal{N}(\mu, \sigma^2) add up to N(nμ,nσ2)\mathcal{N}(n\mu, n\sigma^2). Their average, the sum divided by nn, is N ⁣(μ,σ2n)\mathcal{N}\!\left(\mu, \frac{\sigma^2}{n}\right): lesson 5.7.2 meets this σ2n\frac{\sigma^2}{n} again.

Try it

The first line is the exact answer, then the one with the wrong standard deviation 5.

A million seeded pairs follow. rng.normal takes the standard deviation (2 and 3), not the variance. The sum's mean, standard deviation and share above 5 come out close to 3, 3.606 and 0.290, and the difference has the same spread.

⌘/Ctrl + Enter runs the cell

A sum that leaves its family

Not every family is closed under sums. Take XX and YY independent and exponential with rate λ=1\lambda = 1, so M(t)=11−tM(t) = \frac{1}{1 - t} (lesson 5.6.2). The sum has MS(t)=1(1−t)2M_S(t) = \frac{1}{(1 - t)^2}, which is not λ′λ′−t\frac{\lambda'}{\lambda' - t} for any rate λ′\lambda', so SS is not exponential.

Convolution finds its density. Both densities are 0 below 0, so xx runs from 0 to ss:

fS(s)=∫0se−x e−(s−x) dx=∫0se−s dx=s e−sf_S(s) = \int_0^s e^{-x}\,e^{-(s - x)}\,dx = \int_0^s e^{-s}\,dx = s\,e^{-s}

This holds for s≥0s \ge 0: the density starts at 0, peaks at s=1s = 1 and has mean 2. A sum near 0 needs both waits to be short, which is unlikely. It is the waiting time to the second event of a Poisson stream (lesson 5.4.2), a gamma distribution.

So P(S≤1)=1−2e−1≈0.264241P(S \le 1) = 1 - 2e^{-1} \approx 0.264241; 100,000 seeded sums give 0.2638.

Try it

quad computes the convolution integral at four values of ss, beside se−sse^{-s}.

Then 100,000 seeded sums: the share up to 1, the mean and the variance, near 0.2642, 2 and 2.

⌘/Ctrl + Enter runs the cell

Where independence matters

Every rule in this lesson needs XX and YY independent. The clearest failure is X+X=2XX + X = 2X: one variable added to itself, the opposite of independent.

  • A die. 2X2X takes the values 2, 4, …, 12, each with probability 16\frac{1}{6}. So P(2X=7)=0P(2X = 7) = 0, while two independent dice give 7 with probability 16\frac{1}{6}.
  • The MGF. M2X(t)=MX(2t)M_{2X}(t) = M_X(2t), by the rule for aX+baX + b (lesson 5.6.2), not MX(t)2M_X(t)^2.
  • Exponentials. 2X2X has density 12e−s/2\frac{1}{2}e^{-s/2} (lesson 5.6.1), not se−sse^{-s}. Both have mean 2, but the variance of 2X2X is 4, against 2 for X+YX + Y.
  • Normals. Z+Z=2ZZ + Z = 2Z is N(0,4)\mathcal{N}(0, 4), while two independent standard normals add to N(0,2)\mathcal{N}(0, 2).

Two ways to add exponentials with mean 1. Independent waits rarely sum to near 0; doubling one wait often does. Both have mean 2.

Means always add, independent or not (lesson 5.3.2). Variances add when the terms are uncorrelated (lesson 5.5.2).

The whole distribution of a sum needs more: independence, or the joint distribution. Correlated normals still add to a normal when they are jointly normal (lesson 5.5.3), with 2Cov⁡(X,Y)2\operatorname{Cov}(X, Y) in the variance.

Module 5.7 adds up many independent draws: the law of large numbers and the central limit theorem. Case study 5.6.5 adds up independent normal log returns.

Common mistakes

  1. Add variances, not standard deviations. N(1,4)+N(2,9)\mathcal{N}(1, 4) + \mathcal{N}(2, 9) has standard deviation 13≈3.61\sqrt{13} \approx 3.61, not 5.
  2. Variances add for differences too. Var⁡(X−Y)=13\operatorname{Var}(X - Y) = 13, not 9−49 - 4.
  3. Multiply MGFs; do not add them. MX+MYM_X + M_Y is not even 1 at t=0t = 0.
  4. X+XX + X is not two independent copies. 2X2X has MX(2t)M_X(2t), and a doubled die never shows 7.
  5. Not every family is closed. Two exponentials add to se−sse^{-s}, not to an exponential.
  6. Check independence first. Without it, the product rule and the convolution formula do not apply.

Sums of independent random variables

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

  • For independent XX and YY, the distribution of S=X+YS = X + Y is the convolution: pS(s)=∑xpX(x)pY(s−x)p_S(s) = \sum_x p_X(x)p_Y(s - x), or ∫fX(x)fY(s−x) dx\int f_X(x)f_Y(s - x)\,dx.
  • Two dice: P(S=s)P(S = s) counts the pairs on a diagonal, from 136\frac{1}{36} at 2 up to 636\frac{6}{36} at 7 and back.
  • MX+Y(t)=MX(t)MY(t)M_{X + Y}(t) = M_X(t)M_Y(t), and likewise ψX+Y=ψXψY\psi_{X + Y} = \psi_X\psi_Y: multiply, recognise, and uniqueness names the sum.
  • nn Bernoullis make a binomial; Poissons with rates λ1,λ2\lambda_1, \lambda_2 make rate λ1+λ2\lambda_1 + \lambda_2; N(μ1,σ12)+N(μ2,σ22)=N(μ1+μ2,σ12+σ22)\mathcal{N}(\mu_1, \sigma_1^2) + \mathcal{N}(\mu_2, \sigma_2^2) = \mathcal{N}(\mu_1 + \mu_2, \sigma_1^2 + \sigma_2^2).
  • Two exponentials with rate 1 add to density se−sse^{-s}, not an exponential.
  • Independence is needed: 2X2X has MX(2t)M_X(2t), not MX(t)2M_X(t)^2. Means add always; variances add without correlation.

Free further reading

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