SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 2.6.1 Integration by substitutionConcept · 30 min
      2. 2.6.2 Integration by partsConcept · 30 min
      3. 2.6.3 Improper integrals and the Gaussian integralConcept · 35 min
      4. 2.6.4 Practice set: integration techniquesPractice set · 25 min
      5. 2.6.5 Case study: the normal integrals behind Black–ScholesCase study · 35 min

Level 2, Single-variable calculus 2.6 Integration techniques Lesson 4 of 5

Practice setLesson 2.6.4 in Level 2, Single-variable calculus. About 25 minutes.

Practice set: integration techniques

Substitution

Integration by substitution (lesson 2.6.1)

0 of 6 correct

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

Integration by parts

Integration by parts (lesson 2.6.2)

0 of 6 correct

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

Improper integrals

Improper integrals and the Gaussian integral (lesson 2.6.3)

0 of 6 correct

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

The normal distribution from its density

Write two functions without using scipy.stats.

  1. normal_pdf(x) returns φ(x)=12πe−x2/2\varphi(x) = \frac{1}{\sqrt{2\pi}}e^{-x^2/2}.
  2. normal_cdf(x) returns N(x)=∫−∞xφ(t) dtN(x) = \int_{-\infty}^{x}\varphi(t)\,dt, computed with scipy.integrate.quad and math.inf (lesson 2.6.3).

The tests compare your functions with scipy.stats.norm. They also check that φ\varphi is symmetric, that N(0)=12N(0) = \frac{1}{2}, that N(x)+N(−x)=1N(x) + N(-x) = 1, and the far tails N(−8)N(-8) and N(8)N(8).

N(−8)N(-8) is about 6.2×10−166.2 \times 10^{-16}, so the test asks for it to be within 10−1210^{-12} of 0. Case study 2.6.5 shows why such tiny tail areas need care.

See the tests
from scipy.stats import norm


def test_pdf_at_zero():
    """φ(0) = 1/√(2π), about 0.3989"""
    expect_close(normal_pdf(0.0), norm.pdf(0.0), what="normal_pdf(0)")


def test_pdf_symmetric():
    """φ is symmetric: φ(1.5) = φ(−1.5)"""
    expect_close(normal_pdf(-1.5), normal_pdf(1.5), what="normal_pdf(−1.5) vs normal_pdf(1.5)")


def test_cdf_middle():
    """N(0) = 0.5"""
    expect_close(normal_cdf(0.0), 0.5, what="normal_cdf(0)", rel=1e-8)


def test_cdf_values():
    """N(x) matches scipy.stats.norm.cdf at several points"""
    for x in (-2.0, -0.5, 1.0, 1.96):
        expect_close(normal_cdf(x), norm.cdf(x), what=f"normal_cdf({x})", rel=1e-7)


def test_cdf_symmetry():
    """N(x) + N(−x) = 1: the two tails of the bell have equal area"""
    for x in (0.4, 1.3, 2.5):
        expect_close(normal_cdf(x) + normal_cdf(-x), 1.0, what=f"normal_cdf({x}) + normal_cdf(−{x})", rel=1e-8)


def test_cdf_tails():
    """N(−8) is nearly 0 and N(8) nearly 1"""
    expect_close(normal_cdf(-8.0), 0.0, what="normal_cdf(−8)", abs_tol=1e-12, rel=0)
    expect_close(normal_cdf(8.0), 1.0, what="normal_cdf(8)", rel=1e-9)

Free further reading

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

  • Calculus II

    Paul's Online Notes. Notes.

    Integration techniques, improper integrals, sequences and series.