SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 4.3.1 The Hessian and second-order Taylor expansionConcept · 35 min
      2. 4.3.2 Minima, maxima and saddle pointsConcept · 30 min
      3. 4.3.3 Practice set: second-order methodsPractice set · 20 min
      4. 4.3.4 Case study: delta–gamma–vega P&LCase study · 35 min

Level 4, Multivariable calculus and optimisation 4.3 Second order Lesson 3 of 4

Practice setLesson 4.3.3 in Level 4, Multivariable calculus and optimisation. About 20 minutes.

Practice set: second-order methods

The Hessian and the quadratic copy

The Hessian and second-order Taylor expansion (lesson 4.3.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.

Critical points and the second-derivative test

Minima, maxima and saddle points (lesson 4.3.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.

Coding exercise

Exercise

What kind of critical point?

Write classify(f, a, d=1e-4, tol=1e-4, grad_tol=1e-6). Here f takes a NumPy array of nn numbers and returns one number, and a is the point. Return one of the strings "not critical", "minimum", "maximum", "saddle" or "no verdict".

  1. Turn a into a decimal array. Estimate each partial derivative by a central difference with bump d (lesson 4.1.2). If any has size above grad_tol, return "not critical".
  2. Estimate HH by central differences with bump d: the four-corner formula of lesson 4.1.2 for every entry, as in lesson 4.3.1.
  3. Take the eigenvalues of 12(H+H⊤)\frac{1}{2}(H + H^\top) with np.linalg.eigvalsh. If any has size below tol, return "no verdict". Otherwise apply the test of lesson 4.3.2.

The tests use the cubic and example 2 of lesson 4.3.2, its three-variable function, a maximum in three variables and a minimum in four. They also try a point where HH is positive definite but the gradient is not 0, and x4+y2x^4 + y^2 and −x4+y2-x^4 + y^2 at the origin.

See the tests
import numpy as np


def cubic(p):
    return p[0] ** 3 - 3 * p[0] + p[1] ** 2


def example2(p):
    return 6 * p[0] * p[1] - 2 * p[0] ** 3 - 3 * p[1] ** 2


def three(p):
    return p[0] ** 2 + p[1] ** 2 + p[2] ** 2 - p[0] * p[1] * p[2]


def test_minimum():
    """x³ − 3x + y² has a minimum at (1, 0)"""
    expect_equal(classify(cubic, [1, 0]), "minimum", what="classify(cubic, [1, 0])")


def test_saddle():
    """x³ − 3x + y² has a saddle at (−1, 0)"""
    expect_equal(classify(cubic, [-1, 0]), "saddle", what="classify(cubic, [-1, 0])")


def test_maximum():
    """6xy − 2x³ − 3y² has a maximum at (1, 1)"""
    expect_equal(classify(example2, [1, 1]), "maximum", what="classify(example2, [1, 1])")


def test_saddle_with_zero_corner():
    """6xy − 2x³ − 3y² has a saddle at (0, 0), where f_xx = 0"""
    expect_equal(classify(example2, [0, 0]), "saddle", what="classify(example2, [0, 0])")


def test_not_critical():
    """At (1, 1) the cubic's Hessian is positive definite, but the gradient is (0, 2): not critical"""
    expect_equal(classify(cubic, [1, 1]), "not critical", what="classify(cubic, [1, 1])")


def test_three_variables():
    """x² + y² + z² − xyz: a minimum at the origin and a saddle at (2, 2, 2)"""
    expect_equal(classify(three, [0, 0, 0]), "minimum", what="classify(three, [0, 0, 0])")
    expect_equal(classify(three, [2, 2, 2]), "saddle", what="classify(three, [2, 2, 2])")


def test_maximum_three_variables():
    """−x² − y² − z² + xy has a maximum at the origin"""
    f = lambda p: -p[0] ** 2 - p[1] ** 2 - p[2] ** 2 + p[0] * p[1]
    expect_equal(classify(f, [0, 0, 0]), "maximum", what="classify(-x² - y² - z² + xy, [0, 0, 0])")


def test_four_variables():
    """(x₁ − 1)² + (x₂ − 2)² + (x₃ − 3)² + (x₄ − 4)² has a minimum at (1, 2, 3, 4)"""
    f = lambda p: float(np.sum((np.asarray(p) - np.array([1, 2, 3, 4])) ** 2))
    expect_equal(classify(f, [1, 2, 3, 4]), "minimum", what="classify(sum of squares, [1, 2, 3, 4])")


def test_no_verdict():
    """x⁴ + y² and −x⁴ + y² both give no verdict at the origin: an eigenvalue of H is 0"""
    expect_equal(classify(lambda p: p[0] ** 4 + p[1] ** 2, [0, 0]), "no verdict", what="classify(x⁴ + y², [0, 0])")
    expect_equal(classify(lambda p: -p[0] ** 4 + p[1] ** 2, [0, 0]), "no verdict", what="classify(-x⁴ + y², [0, 0])")


def test_tuple_input():
    """The point may be a tuple of whole numbers: (1, 0) is still the cubic's minimum"""
    expect_equal(classify(cubic, (1, 0)), "minimum", what="classify(cubic, (1, 0))")

Free further reading

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