SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.7.1 The Markov, Chebyshev and Jensen inequalitiesConcept · 35 min
      2. 5.7.2 The law of large numbersConcept · 30 min
      3. 5.7.3 The central limit theoremConcept · 35 min
      4. 5.7.4 Practice set: inequalities and limit theoremsPractice set · 25 min
      5. 5.7.5 Case study: the error of a Monte Carlo priceCase study · 35 min

Level 5, Probability and statistics 5.7 Inequalities and limit theorems Lesson 4 of 5

Practice setLesson 5.7.4 in Level 5, Probability and statistics. About 25 minutes.

Practice set: inequalities and limit theorems

The Markov, Chebyshev and Jensen inequalities

The Markov, Chebyshev and Jensen inequalities (lesson 5.7.1)

0 of 9 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
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.

The law of large numbers

The law of large numbers (lesson 5.7.2)

0 of 8 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
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.

The central limit theorem

The central limit theorem (lesson 5.7.3)

0 of 8 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
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.

Coding exercise

Exercise

How many draws?

Write draws_needed(sigma, eps, delta). It returns the pair (n_chebyshev, n_normal). Each is a number of draws nn that keeps P(∣Xˉn−μ∣≥ε)P(|\bar{X}_n - \mu| \ge \varepsilon) at or below δ\delta.

Here σ\sigma = sigma is the standard deviation of one draw, ε\varepsilon = eps and δ\delta = delta.

  • n_chebyshev is the smallest whole nn with σ2nε2≤δ\frac{\sigma^2}{n\varepsilon^2} \le \delta (lesson 5.7.2): a guarantee for every distribution.
  • n_normal is the smallest whole nn with zσn≤εz\frac{\sigma}{\sqrt{n}} \le \varepsilon, where zz is norm.ppf(1 - delta / 2) (lesson 5.7.3): the central limit theorem's answer.
  • Both are at least 1; with sigma = 0 one draw is enough. Use math.ceil to round up.
  • Raise ValueError if sigma is negative, eps is 0 or below, or delta is not strictly between 0 and 1.

For a die and eps = 0.1, delta = 0.05, the answers are 5,834 and 1,121, as in lessons 5.7.2 and 5.7.3.

See the tests
import math


def test_die():
    """A die (sigma² = 35/12), within 0.1 with probability 0.95: 5834 rolls by Chebyshev, 1121 by the normal"""
    got = draws_needed(math.sqrt(35 / 12), 0.1, 0.05)
    expect_equal(tuple(got), (5834, 1121), what="draws_needed(sqrt(35/12), 0.1, 0.05)")


def test_share():
    """A fair coin's share (sigma = 0.5) within 0.015 with probability 0.95: 22223 and 4269 tosses"""
    got = draws_needed(0.5, 0.015, 0.05)
    expect_equal(tuple(got), (22223, 4269), what="draws_needed(0.5, 0.015, 0.05)")


def test_other_delta():
    """sigma = 2, eps = 0.3, delta = 0.1: the normal uses its 0.95-quantile 1.6449, giving 445 and 121"""
    got = draws_needed(2, 0.3, 0.1)
    expect_equal(tuple(got), (445, 121), what="draws_needed(2, 0.3, 0.1)")


def test_hundred_times():
    """One more digit (eps divided by 10) needs about 100 times the draws"""
    n1 = draws_needed(1.5, 0.05, 0.05)[1]
    n2 = draws_needed(1.5, 0.005, 0.05)[1]
    expect_close(n2 / n1, 100, what="ratio of draws for eps = 0.005 and eps = 0.05", rel=0.01)


def test_chebyshev_is_cautious():
    """Chebyshev's guarantee always asks for at least as many draws as the normal"""
    for delta in [0.5, 0.1, 0.05, 0.01, 0.001]:
        cheb, normal = draws_needed(1.0, 0.01, delta)
        assert cheb >= normal, f"with delta = {delta}, Chebyshev gave {cheb} but the normal gave {normal}"


def test_no_spread():
    """With sigma = 0 every draw is mu, so one draw is enough: (1, 1)"""
    expect_equal(tuple(draws_needed(0, 0.1, 0.05)), (1, 1), what="draws_needed(0, 0.1, 0.05)")


def test_whole_numbers():
    """Both answers are whole numbers of draws"""
    for n in draws_needed(3.0, 0.2, 0.05):
        assert isinstance(n, int), f"expected whole numbers (int), got {n!r} of type {type(n).__name__}"


def test_bad_inputs():
    """A negative sigma, eps of 0 or below, or delta outside (0, 1) raises ValueError"""
    cases = [
        ("sigma = -1", lambda: draws_needed(-1, 0.1, 0.05)),
        ("eps = 0", lambda: draws_needed(1, 0, 0.05)),
        ("eps = -0.1", lambda: draws_needed(1, -0.1, 0.05)),
        ("delta = 0", lambda: draws_needed(1, 0.1, 0)),
        ("delta = 1", lambda: draws_needed(1, 0.1, 1)),
        ("delta = 1.5", lambda: draws_needed(1, 0.1, 1.5)),
    ]
    for name, call in cases:
        try:
            call()
        except ValueError:
            continue
        raise AssertionError(f"expected ValueError for {name}")

Free further reading

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