SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 2.4.1 Maxima and minimaConcept · 25 min
      2. 2.4.2 Concavity and the second derivativeConcept · 25 min
      3. 2.4.3 Newton's method with derivativesConcept · 30 min
      4. 2.4.4 Practice set: using derivativesPractice set · 25 min
      5. 2.4.5 Case study: convexity and risk aversionCase study · 30 min
      6. 2.4.6 Case study: implied volatility by Newton's methodCase study · 30 min

Level 2, Single-variable calculus 2.4 Using derivatives Lesson 3 of 6

ConceptLesson 2.4.3 in Level 2, Single-variable calculus. About 30 minutes.

Newton's method with derivatives

Any slope, from the rules

Lesson 1.3.3 ran Newton's method on a few borrowed slopes: those of x2x^2 and x3x^3, and the fact that adding mxmx adds mm. Module 2.3 now gives the slope of any function built from powers, products, quotients, exponentials and logs. So Newton's method works for all of them.

The step is the same. The tangent at the guess xnx_n is the line y=f(xn)+f′(xn)(x−xn)y = f(x_n) + f'(x_n)(x - x_n) of lesson 2.2.1, and the next guess is where it crosses zero.

Rule: Newton's method

xn+1=xn−f(xn)f′(xn)x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}

f(xn)f(x_n) is a height and f′(xn)f'(x_n) a slope, so their ratio is in input units: the distance to step sideways. The slope must not be 0.

Solving xex=1xe^x = 1

No formula gives xx. So take f(x)=xex−1f(x) = xe^x - 1 and look for its root. The product rule (lesson 2.3.2), with exe^x as its own slope (lesson 2.3.4), gives

f′(x)=ex+xex=ex(1+x)f'(x) = e^x + xe^x = e^x(1 + x)

Start at x0=1x_0 = 1. There f(1)=e−1≈1.718f(1) = e - 1 \approx 1.718 and f′(1)=2e≈5.437f'(1) = 2e \approx 5.437, so x1=1−1.7185.437≈0.684x_1 = 1 - \frac{1.718}{5.437} \approx 0.684.

step nnguess xnx_nf(xn)f(x_n)
10.68393972058572120.355
20.57745447715444980.0287
30.56722973773011710.000239
40.56714329653029590.0000000169
50.5671432904097842×10−162 \times 10^{-16}

The root is x≈0.567143x \approx 0.567143. The last value of ff is zero up to rounding: the computer keeps about 16 digits (lesson 2.1.1).

Try it

The cell runs five steps with the slope from the product rule. Each line prints the step, the guess and ff there.

2.220446049250313e-16 is Python's way of writing 2.2×10−162.2 \times 10^{-16}.

⌘/Ctrl + Enter runs the cell

How fast: the error squares

Write rr for the root and en=xn−re_n = x_n - r for the error of guess nn. Here are the errors for xex−1xe^x - 1 from x0=1x_0 = 1, with the number of correct digits, −log⁡10en-\log_{10} e_n (lesson 1.4.3).

step nnerror ene_ncorrect digitsen÷en−12e_n \div e_{n-1}^2
00.4330.4
10.1170.90.62
20.01032.00.76
30.00008644.10.81
40.000000006128.20.82

The correct digits go 1, 2, 4, 8: they double. The last column settles near 0.82, so each error is about 0.82 times the square of the one before. An error that squares each step is called quadratic convergence.

Rule: Quadratic convergence

en+1≈f′′(r)2f′(r) en2e_{n+1} \approx \frac{f''(r)}{2f'(r)}\, e_n^2

This holds near a root rr where f′(r)≠0f'(r) \neq 0. The constant uses the second derivative of lesson 2.4.2; module 2.7 shows where it comes from.

For xex−1xe^x - 1, f′′(x)=ex(2+x)f''(x) = e^x(2 + x), and the constant at rr is 0.819, the number the table settles on. For x2−2x^2 - 2 of lesson 1.3.3, f′′=2f'' = 2 and f′(2)=22f'(\sqrt{2}) = 2\sqrt{2}, so the constant is 122≈0.354\frac{1}{2\sqrt{2}} \approx 0.354. That is the "about a third" lesson 1.3.3 saw.

At a double root f′(r)=0f'(r) = 0, so the rule fails. That is why lesson 1.3.3 saw the error of (x−1)2(x - 1)^2 only halve each step.

Try it

The cell takes eight steps and uses the last guess as the root. Each line is an error, its digits, and its ratio to the previous error squared.

The last line works out f′′(r)2f′(r)\frac{f''(r)}{2f'(r)} with f′′(x)=ex(2+x)f''(x) = e^x(2 + x).

⌘/Ctrl + Enter runs the cell

The explorer below starts on x3−x−1x^3 - x - 1 from 1.5, the cubic of lesson 1.3.3, whose slope is 3x2−13x^2 - 1 by the power rule (lesson 2.3.1). Press Next step and watch the distance from the root in the readout: about 0.023, then 0.00048, then 0.00000022. Each error is roughly the square of the last, scaled by a constant.

Explore

Press Next step. Each step follows the tangent line at the current guess down to where it crosses zero, which is the next guess.

11.520246
Steps
0
Current guess
1.5
f there
0.875
Distance from the root 1.324718
0.175282042755

Good starts and bad starts

From x0=1x_0 = 1, every guess for xex=1xe^x = 1 landed right of the root: 0.684, then 0.577, then 0.5672. Concavity explains it. f′′(x)=ex(2+x)f''(x) = e^x(2 + x) is positive for x>−2x > -2, so the curve is concave up there and lies above each tangent (lesson 2.4.2).

Follow such a tangent down from xnx_n to zero. There the curve, which lies above the tangent, is still above zero, so the root is further left. Each guess therefore lands between the root and the previous guess: it never overshoots.

From a start left of the root it overshoots once: x0=0x_0 = 0 gives x1=1x_1 = 1, and the guesses then march back from the right.

A start that runs away

g(x)=xe−xg(x) = xe^{-x} has its root at 0. The product rule (lesson 2.3.2), with −e−x-e^{-x} as the slope of e−xe^{-x} (lesson 2.3.4), gives g′(x)=(1−x)e−xg'(x) = (1 - x)e^{-x}, as in lesson 2.4.1. From x0=2x_0 = 2:

step nn1234
guess xnx_n45.33336.56417.7438
g(xn)g(x_n)0.07330.02570.00930.0034

The values of gg shrink towards 0, yet the guesses move away from the root. Past its peak at 1, the curve sinks towards the axis without reaching it, and the tangents get flatter.

Algebra shows it never stops. The step simplifies to x−x1−x=x2x−1x - \frac{x}{1 - x} = \frac{x^2}{x - 1}, which is more than x+1x + 1 whenever x>1x > 1.

At x=1x = 1 the tangent is flat and the step divides by 0. From x0=0.5x_0 = 0.5 the guesses go −0.5-0.5, −0.1667-0.1667, −0.0238-0.0238, −0.0006-0.0006: straight to the root.

Two starts. For xex−1xe^x - 1 the curve bends up, so each tangent lies below it and every guess lands between the root and the last guess. For xe−xxe^{-x} from 2, each tangent is flatter than the last and the guesses run away from the root at 0.

Lesson 1.3.3 met the other failures: a flat tangent, a cycle, a double root, no root, and an unexpected root.

Try it

Four steps of Newton's method on xe−xxe^{-x}, from 2 and from 0.5. Each pair is a guess and the value of gg there.

From 2 the values look as if they are reaching 0, but the guesses are not.

⌘/Ctrl + Enter runs the cell

Newton or bisection?

Bisection (lesson 1.3.2) and Newton's method make opposite trades. Here both solve xex=1xe^x = 1 to 10−1210^{-12}:

bisection on [0,1][0, 1]Newton from 1
needsa sign changea slope and a start
each stephalves the bracketabout doubles the digits
steps to 10−1210^{-12}406
can fail?no, once bracketedyes

Newton's count includes a last tiny step that shows the guess has stopped moving, as in lesson 1.3.3. Bisection needs 40 steps because 2402^{40} is the first power of 2 above 101210^{12}.

Newton with a bracket

Careful code gets both: Newton's speed and bisection's guarantee. Keep a bracket [a,b][a, b] with a sign change. After each guess, shrink the bracket to the half that still changes sign, as bisection does.

Rule: Newton with a bracket

if x−f(x)f′(x) lies inside [a,b],take that step;otherwise take a+b2\begin{gathered} \text{if } x - \frac{f(x)}{f'(x)} \text{ lies inside } [a, b], \\ \text{take that step;} \\ \text{otherwise take } \frac{a + b}{2} \end{gathered}

A Newton step that would leave the bracket, or a flat tangent, is replaced by a bisection step. The root never escapes, and near it the Newton steps take over.

Try it

safe_newton starts at the midpoint and follows the rule above. It returns the root and the number of steps.

The cycle function of lesson 1.3.3, x3−2x+2x^3 - 2x + 2 on [−2,0][-2, 0], takes 7 steps. Plain Newton from the midpoint −1-1 would jump to −4-4 first. xe−xxe^{-x} on [−1,4][-1, 4] takes 7 steps; plain Newton from its midpoint 1.5 runs away to 4.5, then 5.79.

⌘/Ctrl + Enter runs the cell

SciPy's brentq (lesson 1.3.2) mixes safe and fast steps in a similar way, with chords instead of tangents. Practice set 2.4.4 asks you to write this solver, and case study 2.4.6 needs it for options whose price curve is almost flat.

Newton for a minimum

A local minimum is a root of f′f' (lesson 2.4.1), and Newton's method finds roots. Its step then divides by the slope of f′f', which is f′′f''.

Rule: Newton for a critical point

xn+1=xn−f′(xn)f′′(xn)x_{n+1} = x_n - \frac{f'(x_n)}{f''(x_n)}

Newton's method applied to f′f' instead of ff. It finds any critical point, so check the answer with f′′f'' (lesson 2.4.2): positive means a minimum, negative a maximum.

Take f(x)=x4−3x2+xf(x) = x^4 - 3x^2 + x, with f′(x)=4x3−6x+1f'(x) = 4x^3 - 6x + 1 and f′′(x)=12x2−6f''(x) = 12x^2 - 6. From x0=1x_0 = 1 the guesses are 1.166667, 1.132616, 1.130905 and 1.130901. There f′′≈9.35>0f'' \approx 9.35 > 0, so it is a minimum, with value −1.0702-1.0702.

The start decides which critical point you get. From 0, Newton lands on 0.169938, where f′′≈−5.65f'' \approx -5.65: a maximum. From −1-1 it lands on −1.30084-1.30084, a second minimum with the lower value −3.5139-3.5139.

Try it

The loop runs five steps from 1, then prints f′′f'' and ff at the answer.

SciPy's newton(f, x0, fprime=…) runs the same method. Here it gets f′f' and f′′f'', from 0 and from −1-1.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. Use the slope from the rules at the current guess. A wrong derivative still moves the guess, but convergence slows or fails. A central difference (lesson 2.2.2) is a quick check.
  2. A small f(xn)f(x_n) is not a small error. For xe−xxe^{-x} from 2, gg falls to 0.0034 while the guess runs off past 7.
  3. Quadratic convergence needs f′(r)≠0f'(r) \neq 0. At a double root the error only halves.
  4. The start matters. For xe−xxe^{-x}, any start above 1 runs away, and a start at 1 has a flat tangent.
  5. Fast is not safe. When you cannot pick a good start, keep a bracket and bisect whenever a step leaves it.
  6. For a minimum, give Newton f′f' and f′′f'', not ff and f′f', and check the sign of f′′f'' at the answer.

Newton's method with derivatives

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
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.

Summary card

  • Newton's method xn+1=xn−f(xn)f′(xn)x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} works for any ff you can differentiate with the rules of module 2.3.
  • Near a root with f′(r)≠0f'(r) \neq 0, en+1≈f′′(r)2f′(r)en2e_{n+1} \approx \frac{f''(r)}{2f'(r)}e_n^2: the correct digits double each step.
  • On a concave-up rising curve, a start right of the root never overshoots. A start where the curve flattens towards the axis can run away, while f(xn)f(x_n) looks small.
  • Bisection is slow and certain; Newton is fast and can fail. Newton with a bracket bisects whenever a step would leave the bracket.
  • For a critical point, apply Newton to f′f': xn+1=xn−f′(xn)f′′(xn)x_{n+1} = x_n - \frac{f'(x_n)}{f''(x_n)}, then check the sign of f′′f''.

Free further reading

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