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 2 of 5

ConceptLesson 5.2.2 in Level 5, Probability and statistics. About 30 minutes.

Bernoulli, binomial and geometric distributions

Bernoulli trials

A Bernoulli trial is an experiment with two outcomes, called success and failure. Success has probability pp, a number from 0 to 1, and failure 1−p1 - p.

"Success" is only a label for the outcome being counted. A coin landing heads (p=12p = \frac{1}{2}), a die showing a six (p=16p = \frac{1}{6}) and a part failing its test are all Bernoulli trials.

Rule: Bernoulli distribution

pX(1)=p,pX(0)=1−ppX(x)=px(1−p)1−x\begin{gathered} p_X(1) = p, \quad p_X(0) = 1 - p \\[4pt] p_X(x) = p^x (1 - p)^{1 - x} \end{gathered}

XX is 1 for a success and 0 for a failure, so it counts successes in one trial. The second line packs both cases into one formula, for x=0x = 0 or 1.

With p=0p = 0 or p=1p = 1 there is no chance involved: the trial always fails, or always succeeds.

The binomial distribution

Now repeat the trial nn times. The trials are independent and each has the same pp. Let XX be the number of successes; it can be any whole number from 0 to nn.

Take n=3n = 3 and p=0.4p = 0.4. By independence (lesson 5.1.3), the probability of a sequence is the product of its trials' probabilities: SSFSSF has 0.4×0.4×0.6=0.0960.4 \times 0.4 \times 0.6 = 0.096.

sequencessuccesses kkeach sequenceP(X=k)P(X = k)
FFFFFF00.63=0.2160.6^3 = 0.2160.216
SFFSFF, FSFFSF, FFSFFS10.4×0.62=0.1440.4 \times 0.6^2 = 0.1443×0.144=0.4323 \times 0.144 = 0.432
SSFSSF, SFSSFS, FSSFSS20.42×0.6=0.0960.4^2 \times 0.6 = 0.0963×0.096=0.2883 \times 0.096 = 0.288
SSSSSS30.43=0.0640.4^3 = 0.0640.064

Every sequence with kk successes has the same probability, pk(1−p)n−kp^k(1 - p)^{n - k}. The number of such sequences is the number of ways to choose which kk of the nn trials succeed: (nk)\binom{n}{k}, from lesson 5.1.2. Here (31)=(32)=3\binom{3}{1} = \binom{3}{2} = 3.

Rule: Binomial distribution

P(X=k)=(nk)pk(1−p)n−kk=0,1,…,n\begin{gathered} P(X = k) = \binom{n}{k} p^k (1 - p)^{n - k} \\[4pt] k = 0, 1, \ldots, n \end{gathered}

The count of successes in nn independent trials, each with success probability pp. We write X∼Bin⁡(n,p)X \sim \operatorname{Bin}(n, p), read "XX has the binomial distribution with nn trials and probability pp". A Bernoulli trial is the case n=1n = 1.

Ten trials with p=0.3p = 0.3

For n=10n = 10 and p=0.3p = 0.3, three successes have probability (103)×0.33×0.77=120×0.027×0.08235=0.2668\binom{10}{3} \times 0.3^3 \times 0.7^7 = 120 \times 0.027 \times 0.08235 = 0.2668. The whole pmf, to four decimals:

kk012345678
P(X=k)P(X = k)0.02820.12110.23350.26680.20010.10290.03680.00900.0014

k=9k = 9 has probability 0.0001, and k=10k = 10 rounds to 0. The distribution function of lesson 5.2.1 adds up from the left: P(X≤2)=0.0282+0.1211+0.2335=0.3828P(X \le 2) = 0.0282 + 0.1211 + 0.2335 = 0.3828. At the other end, P(X≥5)=1−F(4)=0.1503P(X \ge 5) = 1 - F(4) = 0.1503.

Try it

The first line is the table for n=3n = 3 and p=0.4p = 0.4. Then the cell computes P(X=3)P(X = 3) for n=10n = 10 from the formula, with math.comb. binom.pmf, binom.cdf and binom.sf from scipy.stats give pXp_X, FXF_X and 1−FX1 - F_X.

Then 100,000 runs of 10 trials, with a fixed seed: each row of trials is one run. In this run the three shares are within 0.001 of the exact answers.

⌘/Ctrl + Enter runs the cell

binom.sf(4, n, p) is P(X>4)P(X > 4), which is P(X≥5)P(X \ge 5). To get P(X≥k)P(X \ge k), ask for binom.sf(k - 1, n, p).

None, all and at least one

Three cases come up often and need no counting. No successes means every trial fails, and all successes means every trial succeeds. "At least one" is the complement of none (lesson 5.1.1).

Rule: None, all, at least one

P(X=0)=(1−p)nP(X=n)=pnP(X≥1)=1−(1−p)n\begin{gathered} P(X = 0) = (1 - p)^n \\[4pt] P(X = n) = p^n \\[4pt] P(X \ge 1) = 1 - (1 - p)^n \end{gathered}

For 10 trials with p=0.3p = 0.3, none has probability 0.710=0.02820.7^{10} = 0.0282, and at least one 0.97180.9718.

A tempting shortcut is wrong. In 10 rolls of a die, the chance of at least one six is 1−(56)10=0.83851 - \left(\frac{5}{6}\right)^{10} = 0.8385, not 10×1610 \times \frac{1}{6}, which is more than 1.

The shape

With p=12p = \frac{1}{2} the pmf is symmetric: P(X=k)=P(X=n−k)P(X = k) = P(X = n - k), because (nk)=(nn−k)\binom{n}{k} = \binom{n}{n - k}. For n=10n = 10, both k=3k = 3 and k=7k = 7 have probability 0.1172.

With pp below one half, the bars pile up on the left, with a long tail to the right. Above one half, the picture is the mirror image.

The failures are a binomial count too: if X∼Bin⁡(n,p)X \sim \operatorname{Bin}(n, p), then n−X∼Bin⁡(n,1−p)n - X \sim \operatorname{Bin}(n, 1 - p). So P(X=7)P(X = 7) for p=0.8p = 0.8 equals P(X=3)P(X = 3) for p=0.2p = 0.2: both are 0.2013.

Try it

The first line checks the symmetry for p=12p = \frac{1}{2}, the second the mirror between p=0.8p = 0.8 and p=0.2p = 0.2.

The last line compares at least one six in 10 rolls with the wrong shortcut 10×1610 \times \frac{1}{6}.

⌘/Ctrl + Enter runs the cell

Try it below. Set the interval from 0 to 2 and check P(X≤2)=0.3828P(X \le 2) = 0.3828; then move pp from 0.1 to 0.9 and watch the bars slide across. The dashed line marks the long-run average of XX, which lesson 5.3.1 defines; lesson 5.3.2 shows it is npnp.

Explore

Each bar is the probability of one value. Change the parameters, then set an interval: the shaded bars add up to its probability.

051000.10.2

The dashed line is the mean.

Probability
P(2 ≤ X ≤ 4) = 0.7004
Mean
3
Variance
2.1, so the standard deviation is 1.4491

When the binomial does not apply

The binomial needs four things: a fixed number of trials nn, two outcomes per trial, the same pp every time, and independent trials. Check each before using it.

Draw two cards from a shuffled deck of 52 without putting the first back, and count the aces. The chance of an ace changes after the first card, so the trials are not independent. By counting (lesson 5.1.2), P(two aces)=(42)÷(522)=1221=0.004525P(\text{two aces}) = \binom{4}{2} \div \binom{52}{2} = \frac{1}{221} = 0.004525.

The binomial with n=2n = 2 and p=452=113p = \frac{4}{52} = \frac{1}{13} would give (113)2=0.005917\left(\frac{1}{13}\right)^2 = 0.005917: right if the first card goes back, wrong here. Counts from draws without replacement follow the hypergeometric distribution, named here only.

Try it

Cards 0 to 3 are the aces. Sorting 52 random numbers shuffles the deck, one row per shuffle, and the first two columns are the cards drawn.

rng.integers instead draws each card from the full deck, as if the first went back. In this seeded run the shares are 0.00453 and 0.00552, against the exact 0.004525 and 0.005917.

⌘/Ctrl + Enter runs the cell

When the number of trials is not fixed in advance, the next section's distribution may be the one you need.

The geometric distribution

Repeat independent trials with success probability pp until the first success. Let XX be the number of trials this takes, the success included. XX can be 1,2,3,…1, 2, 3, \ldots, with no upper limit.

X=kX = k means k−1k - 1 failures and then a success. By independence, that has probability (1−p)k−1p(1 - p)^{k - 1}p.

Rule: Geometric distribution

P(X=k)=(1−p)k−1pk=1,2,3,…\begin{gathered} P(X = k) = (1 - p)^{k - 1} p \\[4pt] k = 1, 2, 3, \ldots \end{gathered}

The number of trials up to and including the first success, for 0<p≤10 < p \le 1. We write X∼Geom⁡(p)X \sim \operatorname{Geom}(p). Each extra trial multiplies the probability by 1−p1 - p.

Roll a die until a six appears, so p=16p = \frac{1}{6}. The first six comes on roll 1 with probability 16=0.1667\frac{1}{6} = 0.1667, on roll 2 with 56×16=536=0.1389\frac{5}{6} \times \frac{1}{6} = \frac{5}{36} = 0.1389, and on roll 3 with 25216=0.1157\frac{25}{216} = 0.1157.

The probabilities add up to 1. They form a geometric series with first term pp and ratio 1−p1 - p, whose sum is p1−(1−p)=1\frac{p}{1 - (1 - p)} = 1 by lesson 1.5.3. With p=0p = 0 the series is all zeros: a success never comes.

The tail

X>kX > k means the first kk trials all fail. So the tail has a short formula, and the distribution function follows from it.

Rule: Geometric tail

P(X>k)=(1−p)kFX(k)=1−(1−p)k\begin{gathered} P(X > k) = (1 - p)^k \\[4pt] F_X(k) = 1 - (1 - p)^k \end{gathered}

For a whole number k≥0k \ge 0. The second line is the complement rule, as in lesson 5.2.1.

With a die, P(X>6)=(56)6=0.3349P(X > 6) = \left(\frac{5}{6}\right)^6 = 0.3349: about one time in three, six rolls bring no six. And F(4)=1−(56)4=0.5177F(4) = 1 - \left(\frac{5}{6}\right)^4 = 0.5177, so a six arrives within four rolls about half the time: lesson 5.1.3's chance of at least one six in 4 rolls.

The number of rolls up to the first six. Each bar is 56\frac{5}{6} of the one before. The highlighted tail, which goes on past 24, holds (56)6=0.335\left(\frac{5}{6}\right)^6 = 0.335 of the probability.

How many rolls make you 95% sure of a six? You need (56)k≤0.05\left(\frac{5}{6}\right)^k \le 0.05, so k≥ln⁡0.05ln⁡(5/6)=16.43k \ge \frac{\ln 0.05}{\ln(5/6)} = 16.43 by lesson 1.4.4. Seventeen rolls are enough: (56)17=0.0451\left(\frac{5}{6}\right)^{17} = 0.0451, while (56)16=0.0541\left(\frac{5}{6}\right)^{16} = 0.0541 is not yet below 0.05.

Trials or failures?

Some books and libraries count the failures before the first success instead, Y=X−1Y = X - 1, with values 0,1,2,…0, 1, 2, \ldots and P(Y=j)=(1−p)jpP(Y = j) = (1 - p)^j p. Check which one a formula uses. scipy.stats.geom and NumPy's rng.geometric both count trials, like this lesson.

Try it

geom.pmf, geom.sf and geom.cdf give the probabilities above. loc=-1 shifts the values down by 1, to count failures: P(Y=0)=P(X=1)=0.25P(Y = 0) = P(X = 1) = 0.25 for p=0.25p = 0.25.

The last lines roll until a six 100,000 times with a fixed seed. In this run 0.3344 of the runs need more than six rolls, and the smallest count is 1, as it must be.

⌘/Ctrl + Enter runs the cell

Lesson 5.2.3 lets the number of trials grow while successes become rare, which gives the Poisson distribution. Lesson 5.4.2 meets the continuous version of a waiting time, and case study 5.2.5 counts defaults in a loan portfolio with the binomial.

Common mistakes

  1. Do not forget (nk)\binom{n}{k}. Exactly two sixes in five rolls has probability 10×(16)2(56)3=0.160810 \times \left(\frac{1}{6}\right)^2\left(\frac{5}{6}\right)^3 = 0.1608, not 0.0161: there are ten orders.
  2. "At least one" is 1−(1−p)n1 - (1 - p)^n, not npnp. The product npnp can exceed 1.
  3. sf(k) is P(X>k)P(X > k). For P(X≥k)P(X \ge k) use sf(k - 1).
  4. Check that the trials are independent with the same pp. Cards drawn without replacement are not binomial.
  5. Trials or failures? A geometric formula may count trials (from 1) or failures before the first success (from 0).
  6. The geometric tail has kk in the power. P(X>k)=(1−p)kP(X > k) = (1 - p)^k; (1−p)k−1p(1 - p)^{k - 1}p is the single value P(X=k)P(X = k).

Bernoulli, binomial and geometric distributions

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 Bernoulli trial succeeds with probability pp: pX(1)=pp_X(1) = p, pX(0)=1−pp_X(0) = 1 - p.
  • The number of successes in nn independent trials with the same pp is Bin⁡(n,p)\operatorname{Bin}(n, p): P(X=k)=(nk)pk(1−p)n−kP(X = k) = \binom{n}{k}p^k(1 - p)^{n - k} for k=0,…,nk = 0, \ldots, n.
  • P(X=0)=(1−p)nP(X = 0) = (1 - p)^n and P(X≥1)=1−(1−p)nP(X \ge 1) = 1 - (1 - p)^n. The pmf is symmetric for p=12p = \frac{1}{2}, and n−X∼Bin⁡(n,1−p)n - X \sim \operatorname{Bin}(n, 1 - p).
  • The number of trials up to the first success is Geom⁡(p)\operatorname{Geom}(p): P(X=k)=(1−p)k−1pP(X = k) = (1 - p)^{k - 1}p for k=1,2,…k = 1, 2, \ldots, with tail P(X>k)=(1−p)kP(X > k) = (1 - p)^k.
  • In scipy.stats, binom and geom (which counts trials) have .pmf, .cdf and .sf; sf(k) is P(X>k)P(X > k).

Free further reading

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