SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.2.1 Random variables, PMFs and CDFsConcept · 25 min
      2. 5.2.2 Bernoulli, binomial and geometric distributionsConcept · 30 min
      3. 5.2.3 The Poisson distributionConcept · 30 min
      4. 5.2.4 Practice set: discrete distributionsPractice set · 25 min
      5. 5.2.5 Case study: the one-period binomial model, and counting defaultsCase study · 35 min

Level 5, Probability and statistics 5.2 Discrete random variables Lesson 1 of 5

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

Random variables, PMFs and CDFs

A number for each outcome

Lesson 5.1.1 described an experiment by its sample space Ω\Omega (omega), the set of all its outcomes. Often what matters is a number that each outcome produces: a count, a total, a score. A random variable is that number.

Toss a coin twice. The sample space is {HH,HT,TH,TT}\{HH, HT, TH, TT\}, four equally likely outcomes. Let XX be the number of heads.

outcomeHHHHHTHTTHTHTTTT
XX, the number of heads2110
YY, heads minus tails200−2-2

Rule: Random variable

X:Ω→RX : \Omega \to \mathbb{R}

A rule that gives a real number to each outcome: a function (lesson 1.1.1) from Ω\Omega to the real numbers R\mathbb{R}. A random variable is written with a capital letter, XX; a value it can take is written in lower case, xx.

The same experiment can carry many random variables. YY above is heads minus tails, and it takes the values −2-2, 0 and 2. A random variable has the units of what it counts or measures: heads, points on a die, dollars won.

Each statement about XX is an event, a set of outcomes. The event {X=1}\{X = 1\} is {HT,TH}\{HT, TH\}, and {X≤1}\{X \le 1\} is {HT,TH,TT}\{HT, TH, TT\}. So the probability rules of module 5.1 apply to them.

A random variable is discrete when its values can be listed: finitely many, or 0,1,2,…0, 1, 2, \ldots without end. This module is about discrete random variables. Module 5.4 treats continuous ones, which can take any value in an interval.

Try it

The cell lists the four outcomes and works out XX and YY for each one. Then it adds the probability 14\frac{1}{4} of each outcome to the value it produces.

Fraction keeps the probabilities exact, so 12\frac{1}{2} prints as 1/2.

⌘/Ctrl + Enter runs the cell

The probability mass function

The probability mass function (pmf) of XX gives the probability of each value. To find P(X=x)P(X = x), add the probabilities of all the outcomes that produce xx.

For two tosses, X=1X = 1 comes from two outcomes, HTHT and THTH. So P(X=1)=24=12P(X = 1) = \frac{2}{4} = \frac{1}{2}, while P(X=0)=P(X=2)=14P(X = 0) = P(X = 2) = \frac{1}{4}.

Rule: Probability mass function

pX(x)=P(X=x)pX(x)≥0,∑xpX(x)=1\begin{gathered} p_X(x) = P(X = x) \\[4pt] p_X(x) \ge 0, \quad \sum_x p_X(x) = 1 \end{gathered}

The sum runs over every value of XX. The events {X=x}\{X = x\} for different values never overlap and together cover Ω\Omega, so their probabilities add up to 1 (the axioms of lesson 5.1.1). At any number that is not a value, pX(x)=0p_X(x) = 0.

A pmf can be given by a formula. p(k)=k10p(k) = \frac{k}{10} for k=1,2,3,4k = 1, 2, 3, 4 is a pmf: the four values are positive and add up to 1010=1\frac{10}{10} = 1. The same formula for k=1,…,5k = 1, \ldots, 5 is not one, because the five values add up to 1510\frac{15}{10}.

The larger of two dice

Roll two fair dice and let MM be the larger of the two numbers; on a double, it is that number. The 36 outcomes are equally likely. Each cell shows MM, with the first die down the side and the second across the top.

123456
1123456
2223456
3333456
4444456
5555556
6666666

Count the cells for each value. M=1M = 1 in 1 cell, M=2M = 2 in 3, and so on up to M=6M = 6 in 11.

mm123456
cells1357911
pM(m)p_M(m)136\frac{1}{36}336\frac{3}{36}536\frac{5}{36}736\frac{7}{36}936\frac{9}{36}1136\frac{11}{36}

The counts are the odd numbers, so pM(m)=2m−136p_M(m) = \frac{2m - 1}{36}. They add up to 36, so the pmf adds up to 1. The next section finds the same formula by algebra.

Try it

The cell counts the 36 cells for each value of MM. Fraction reduces 336\frac{3}{36} to 112\frac{1}{12}, so the count is printed too.

Then it rolls two dice 100,000 times with a fixed seed and prints the share of rolls for each value. In this seeded run every share is within 0.003 of the exact pmf.

⌘/Ctrl + Enter runs the cell

The distribution function

The distribution function of XX, written FXF_X, gives FX(x)=P(X≤x)F_X(x) = P(X \le x): the probability that XX is at most xx. It is also called the cumulative distribution function, or CDF. It is defined at every real number xx, not only at the values of XX.

For MM, add the pmf from the left. FM(1)=136F_M(1) = \frac{1}{36}, FM(2)=1+336=436F_M(2) = \frac{1 + 3}{36} = \frac{4}{36}, and so on.

mm123456
FM(m)×36F_M(m) \times 36149162536

The totals are squares, and algebra says why. M≤mM \le m means both dice show at most mm. Each does so with probability m6\frac{m}{6}, and the dice are independent, so FM(m)=(m6)2F_M(m) = \left(\frac{m}{6}\right)^2 by lesson 5.1.3.

Rule: Distribution function

FX(x)=P(X≤x)=∑k≤xpX(k)\begin{gathered} F_X(x) = P(X \le x) \\[4pt] = \sum_{k \le x} p_X(k) \end{gathered}

The sum runs over the values kk of XX up to xx. FXF_X never decreases, is 0 to the left of every value and 1 to the right of them all. It is flat between values and jumps at each value kk by pX(k)p_X(k).

Between two values nothing is added, so the graph of FF is a staircase. FM(2.5)=FM(2)=436F_M(2.5) = F_M(2) = \frac{4}{36}, because MM cannot be 2.5. Below the smallest value FM(x)=0F_M(x) = 0, so FM(0.5)=0F_M(0.5) = 0; from 6 on, FM(x)=1F_M(x) = 1.

At each value the staircase takes the upper level. FM(2)F_M(2) counts M=2M = 2 itself, because ≤\le includes the end. On the graph, a filled dot marks the level at the value and an open dot the level just before it.

The pmf of MM and its distribution function. The two highlighted bars, 536+736\frac{5}{36} + \frac{7}{36}, are the rise of the staircase from F(2)=436F(2) = \frac{4}{36} to F(4)=1636F(4) = \frac{16}{36}: both give P(2<M≤4)=13P(2 < M \le 4) = \frac{1}{3}.

From FF back to the pmf

The jump at each value is its probability. For a random variable whose values are whole numbers:

pX(k)=FX(k)−FX(k−1)p_X(k) = F_X(k) - F_X(k - 1)

For MM, the algebra gives pM(m)=m2−(m−1)236=2m−136p_M(m) = \frac{m^2 - (m - 1)^2}{36} = \frac{2m - 1}{36}. That is the formula the counting found.

Try it

np.cumsum adds up the pmf from the left: the partial sums of lesson 1.5.2. Multiplied by 36, they are the squares of 1 to 6.

np.diff takes the jumps back. With a 0 in front, it returns the pmf.

⌘/Ctrl + Enter runs the cell

Probabilities of intervals

F(b)F(b) counts every value up to bb. Subtract F(a)F(a), everything up to aa, and what is left are the values above aa and up to bb.

Rule: Probability of an interval

P(a<X≤b)=FX(b)−FX(a)P(X>a)=1−FX(a)\begin{gathered} P(a < X \le b) = F_X(b) - F_X(a) \\[4pt] P(X > a) = 1 - F_X(a) \end{gathered}

The left end is left out and the right end is kept. The second line is the complement rule of lesson 5.1.1: X>aX > a is "not X≤aX \le a".

For MM, P(2<M≤4)=1636−436=1236=13P(2 < M \le 4) = \frac{16}{36} - \frac{4}{36} = \frac{12}{36} = \frac{1}{3}. The bars at 3 and 4 give the same, 536+736\frac{5}{36} + \frac{7}{36}. And P(M>4)=1−1636=59P(M > 4) = 1 - \frac{16}{36} = \frac{5}{9}, the chance that at least one die shows 5 or 6.

Which ends are included

For a discrete random variable, << and ≤\le give different answers: the end can carry probability. When the values are whole numbers, move to the neighbouring whole number.

probabilityfrom FFfor MM
P(X≤b)P(X \le b)F(b)F(b)P(M≤4)=1636P(M \le 4) = \frac{16}{36}
P(X<b)P(X < b)F(b−1)F(b - 1)P(M<4)=936P(M < 4) = \frac{9}{36}
P(X>a)P(X > a)1−F(a)1 - F(a)P(M>4)=2036P(M > 4) = \frac{20}{36}
P(X≥a)P(X \ge a)1−F(a−1)1 - F(a - 1)P(M≥4)=2736P(M \ge 4) = \frac{27}{36}
P(a≤X≤b)P(a \le X \le b)F(b)−F(a−1)F(b) - F(a - 1)P(3≤M≤4)=1236P(3 \le M \le 4) = \frac{12}{36}

For a continuous random variable (module 5.4) a single value has probability 0, and the ends stop mattering.

Try it

rv_discrete from scipy.stats turns a list of values and their probabilities into a distribution. Its .pmf, .cdf and .sf give pXp_X, FXF_X and 1−FX1 - F_X.

The third line gives P(M<4)=F(3)P(M < 4) = F(3) and P(M≥4)=1−F(3)P(M \ge 4) = 1 - F(3) in 36ths, as in the table. The last line counts the simulated rolls with 2<M≤42 < M \le 4. In this seeded run the share is 0.3325, against the exact 13\frac{1}{3}.

⌘/Ctrl + Enter runs the cell

Lesson 5.2.2 meets the first named distributions, whose pmfs are formulas, and scipy.stats has them ready-made with the same .pmf, .cdf and .sf. Lesson 5.3.1 uses the pmf to define the average value of XX.

Common mistakes

  1. XX is the rule; xx is a value. Write P(X=3)P(X = 3), the probability that the random variable equals 3, not P(3)P(3).
  2. Count every outcome that gives the value. M=2M = 2 comes from three outcomes, (1,2)(1, 2), (2,1)(2, 1) and (2,2)(2, 2), not two.
  3. A pmf adds up to 1. If the values add up to anything else, a value is missing or a probability is wrong.
  4. FF is defined between values too. It is flat there: FM(3.7)=FM(3)F_M(3.7) = F_M(3).
  5. Watch the ends. P(X<4)=F(3)P(X < 4) = F(3), not F(4)F(4), and F(b)−F(a)F(b) - F(a) leaves aa out.
  6. P(X≥a)P(X \ge a) is 1−F(a−1)1 - F(a - 1). 1−F(a)1 - F(a) is P(X>a)P(X > a), which leaves out X=aX = a.

Random variables, PMFs and CDFs

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

  • A random variable XX gives a number to each outcome. Statements about it, such as {X=x}\{X = x\} or {X≤x}\{X \le x\}, are events.
  • Its pmf is pX(x)=P(X=x)p_X(x) = P(X = x): never negative, and adding up to 1 over the values.
  • Its distribution function FX(x)=P(X≤x)F_X(x) = P(X \le x) is a staircase, defined at every xx: flat between values, jumping by pX(k)p_X(k) at each value kk.
  • P(a<X≤b)=FX(b)−FX(a)P(a < X \le b) = F_X(b) - F_X(a) and P(X>a)=1−FX(a)P(X > a) = 1 - F_X(a). For whole-number values, pX(k)=FX(k)−FX(k−1)p_X(k) = F_X(k) - F_X(k - 1), and the ends of an interval matter.

Free further reading

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