SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.1.1 What a function is: domain, range and notationConcept · 25 min
      2. 1.1.2 Transformations and piecewise functionsConcept · 30 min
      3. 1.1.3 Composition and inverse functionsConcept · 25 min
      4. 1.1.4 Practice set: functionsPractice set · 20 min
      5. 1.1.5 Case study: option payoff diagramsCase study · 30 min

Level 1, Precalculus 1.1 Functions and graphs Lesson 4 of 5

Practice setLesson 1.1.4 in Level 1, Precalculus. About 20 minutes.

Practice set: functions

Domain and range

Domain and range (lesson 1.1.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.

Transformations and pieces

Transformations and pieces (lesson 1.1.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.

Composition and inverses

Composition and inverses (lesson 1.1.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

Functions that build functions

Write two functions. Both return a function, as compose did in lesson 1.1.3.

  1. compose(outer, inner) returns the function x↦outer(inner(x))x \mapsto \text{outer}(\text{inner}(x)).
  2. inverse_linear(a, b) returns the inverse of f(x)=ax+bf(x) = ax + b. Raise ValueError when a == 0, because a flat line has no inverse.

The tests call your results with numbers and with NumPy arrays.

See the tests
import numpy as np


def _double_plus_one(x):
    return 2 * x + 1


def _square(x):
    return x**2


def test_compose_returns_function():
    """compose(f, g) returns something you can call"""
    h = compose(_double_plus_one, _square)
    assert callable(h), f"expected a function, got {h!r}"


def test_compose_inner_first():
    """compose(f, g)(3) applies g first: f(g(3)) = 19"""
    expect_close(compose(_double_plus_one, _square)(3), 19, what="compose(f, g)(3)")


def test_compose_order_matters():
    """compose(g, f)(3) is g(f(3)) = 49"""
    expect_close(compose(_square, _double_plus_one)(3), 49, what="compose(g, f)(3)")


def test_compose_arrays():
    """Composition works on a NumPy array"""
    x = np.array([0.0, 1.0, 2.0])
    expect_close(compose(_double_plus_one, _square)(x), 2 * x**2 + 1, what="compose(f, g) on [0, 1, 2]")


def test_inverse_simple():
    """The inverse of 2x + 3 sends 13 back to 5"""
    expect_close(inverse_linear(2, 3)(13), 5.0, what="inverse_linear(2, 3)(13)")


def test_inverse_round_trip():
    """Going there and back returns the input, for f(x) = −0.5x + 4"""
    x = np.array([-3.0, 0.0, 1.5, 8.0])
    expect_close(inverse_linear(-0.5, 4)(-0.5 * x + 4), x, what="f⁻¹(f(x)) for several x")


def test_flat_line_has_no_inverse():
    """inverse_linear(0, 7) raises ValueError"""
    try:
        inverse_linear(0, 7)
    except ValueError:
        return
    raise AssertionError("expected ValueError for a == 0")

Free further reading

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