SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 2.5.1 Area and Riemann sumsConcept · 30 min
      2. 2.5.2 AntiderivativesConcept · 25 min
      3. 2.5.3 The fundamental theorem of calculusConcept · 30 min
      4. 2.5.4 Practice set: integrationPractice set · 25 min
      5. 2.5.5 Case study: present value of a continuous cash flowCase study · 35 min

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

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

Practice set: integration

Riemann sums

Area and Riemann sums (lesson 2.5.1)

0 of 7 correct

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

Antiderivatives

Antiderivatives (lesson 2.5.2)

0 of 7 correct

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

The fundamental theorem of calculus (lesson 2.5.3)

0 of 7 correct

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

Riemann sums with a choice of rule

Write riemann(f, a, b, n, rule="mid") that returns the Riemann sum of f on [a, b] with n strips. It takes heights at the "left" end, the "right" end or the "mid"point of each strip. Raise ValueError for any other rule.

f accepts NumPy arrays, so you can evaluate all the heights at once. Use Δx=b−an\Delta x = \frac{b - a}{n} as it stands. Then a curve below the axis gives a negative sum, and so does a reversed interval with a > b (lesson 2.5.3).

See the tests
import numpy as np


def test_left_four_strips():
    """Left sum of x² on [0, 1] with 4 strips is 0.21875"""
    expect_close(riemann(np.square, 0, 1, 4, "left"), 0.21875, what='riemann(x², 0, 1, 4, "left")')


def test_right_four_strips():
    """Right sum of x² on [0, 1] with 4 strips is 0.46875"""
    expect_close(riemann(np.square, 0, 1, 4, "right"), 0.46875, what='riemann(x², 0, 1, 4, "right")')


def test_midpoint_converges():
    """The midpoint sum of x² on [0, 1] with 1000 strips is within 1e-6 of 1/3"""
    expect_close(riemann(np.square, 0, 1, 1000), 1 / 3, what="midpoint sum, 1000 strips", abs_tol=1e-6, rel=0)


def test_other_interval():
    """Midpoint sum of eˣ on [0, 2] with 2000 strips is close to e² − 1"""
    expect_close(riemann(np.exp, 0, 2, 2000), np.e**2 - 1, what="midpoint sum of eˣ on [0, 2]", rel=1e-6)


def test_bad_rule():
    """An unknown rule raises ValueError"""
    try:
        riemann(np.square, 0, 1, 10, "top")
    except ValueError:
        return
    raise AssertionError('expected ValueError for rule="top"')


def test_below_axis():
    """A curve below the axis gives a negative sum: x − 1 on [0, 1] gives −0.5"""
    expect_close(riemann(lambda x: x - 1, 0, 1, 10), -0.5, what="midpoint sum of x − 1 on [0, 1]")


def test_reversed_interval():
    """Running from 1 back to 0 flips the sign: x² gives about −1/3"""
    expect_close(riemann(np.square, 1, 0, 1000), -1 / 3, what="riemann(x², 1, 0, 1000)", abs_tol=1e-6, rel=0)

Free further reading

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