SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons

Level 0, Orientation and fluency 0.2 Reading maths Lesson 3 of 4

Practice setLesson 0.2.3 in Level 0, Orientation and fluency. About 15 minutes.

Practice: reading formulas

Symbols, sets and functions

Symbols and functions (lesson 0.2.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.
Check yourself
Let B={1,4,9,16}B = \{1, 4, 9, 16\}. Which statement is false?

Sums and products

Sums and products (lesson 0.2.2)

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.

Coding exercise

Exercise

Σ and Π as Python functions

Write two functions. Each takes a function term of the index, and the two limits.

  1. sigma(term, lower, upper) returns ∑i=lowerupperterm(i)\sum_{i=\text{lower}}^{\text{upper}} \text{term}(i).
  2. product(term, lower, upper) returns ∏i=lowerupperterm(i)\prod_{i=\text{lower}}^{\text{upper}} \text{term}(i).

Both limits are included. When upper < lower there are no terms: return 0 for the sum and 1 for the product, as in lesson 0.2.2. The tests pass in functions such as lambda i: i**2.

See the tests
def test_sum_of_squares():
    """The sum of i² for i from 1 to 4 is 30"""
    expect_close(sigma(lambda i: i**2, 1, 4), 30, what="sigma(lambda i: i**2, 1, 4)")


def test_upper_limit_included():
    """The upper limit is included: the sum of i for i from 1 to 100 is 5050"""
    expect_close(sigma(lambda i: i, 1, 100), 5050, what="sigma(lambda i: i, 1, 100)")


def test_other_lower_limit():
    """The sum can start anywhere: 2i − 1 for i from 2 to 5 is 24"""
    expect_close(sigma(lambda i: 2 * i - 1, 2, 5), 24, what="sigma(lambda i: 2*i - 1, 2, 5)")


def test_constant_term():
    """Adding 3 five times gives 15"""
    expect_close(sigma(lambda i: 3, 1, 5), 15, what="sigma(lambda i: 3, 1, 5)")


def test_empty_sum():
    """An empty sum (upper below lower) is 0"""
    expect_close(sigma(lambda i: i, 1, 0), 0, what="sigma(lambda i: i, 1, 0)")


def test_product_of_integers():
    """The product of i for i from 1 to 5 is 120"""
    expect_close(product(lambda i: i, 1, 5), 120, what="product(lambda i: i, 1, 5)")


def test_growth_factors():
    """Three growth factors 1.1 × 1.2 × 1.3 multiply to 1.716"""
    expect_close(product(lambda i: 1 + 0.1 * i, 1, 3), 1.1 * 1.2 * 1.3, what="product(lambda i: 1 + 0.1*i, 1, 3)")


def test_empty_product():
    """An empty product (upper below lower) is 1"""
    expect_close(product(lambda i: i, 3, 2), 1, what="product(lambda i: i, 3, 2)")

Free further reading

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