SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 2.7.1 Taylor polynomialsConcept · 30 min
      2. 2.7.2 Standard series and the size of the errorConcept · 35 min
      3. 2.7.3 Practice set: Taylor seriesPractice set · 20 min
      4. 2.7.4 Case study: duration–convexity and delta–gammaCase study · 35 min

Level 2, Single-variable calculus 2.7 Taylor series Lesson 2 of 4

ConceptLesson 2.7.2 in Level 2, Single-variable calculus. About 35 minutes.

Standard series and the size of the error

From polynomials to series

Lesson 2.7.1 built the Taylor polynomial pnp_n from the first nn derivatives at aa. Let nn grow without end and you get an infinite series, the Taylor series of ff about aa.

As in lesson 1.5.3, an infinite series means the limit of its partial sums. Here the partial sums are the Taylor polynomials p0,p1,p2,…p_0, p_1, p_2, \ldots, so the question is whether pn(x)p_n(x) settles on f(x)f(x).

Rule: Taylor series

f(x)=∑k=0∞f(k)(a)k! (x−a)kf(x) = \sum_{k=0}^{\infty} \frac{f^{(k)}(a)}{k!}\,(x - a)^k

This holds at every xx where the partial sums pn(x)p_n(x) settle on f(x)f(x). This lesson finds where that is for five standard series, all about a=0a = 0.

The series for exe^x

Every derivative of exe^x is exe^x (lesson 2.3.4), which is 1 at 0. So every coefficient is 1k!\frac{1}{k!}.

Rule: Series for the exponential

ex=1+x+x22!+x33!+⋯for every x\begin{gathered} e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots \\ \text{for every } x \end{gathered}

The terms shrink fast because k!k! eventually outgrows any power xkx^k. The Proof Gym (stage PG5) proves that the series settles on exe^x for every xx.

At x=1x = 1 the series gives e=1+1+12+16+⋯e = 1 + 1 + \frac{1}{2} + \frac{1}{6} + \cdots. The partial sums are 2.5, 2.6667, 2.7083, 2.7167 and 2.7181 after degrees 2 to 6. After degree 10 the gap to ee is only 2.7×10−82.7 \times 10^{-8}.

Sine and cosine

The derivatives of sin⁡x\sin x go round the cycle of four from lesson 2.3.5: sin⁡\sin, cos⁡\cos, −sin⁡-\sin, −cos⁡-\cos. At 0 their values are 0, 1, 0, −1-1, then the cycle repeats.

So the even powers drop out, and the odd ones alternate in sign. Cosine starts one step along the cycle, at 1, 0, −1-1, 0, so it keeps only the even powers.

Rule: Series for sine and cosine

sin⁡x=x−x33!+x55!−⋯cos⁡x=1−x22!+x44!−⋯for every x, in radians\begin{gathered} \sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \cdots \\[4pt] \cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \cdots \\[4pt] \text{for every } x, \text{ in radians} \end{gathered}

Sine has only odd powers, like its symmetry sin⁡(−x)=−sin⁡x\sin(-x) = -\sin x; cosine has only even powers, like cos⁡(−x)=cos⁡x\cos(-x) = \cos x (lesson 1.7.1).

The first terms are old friends. sin⁡x≈x\sin x \approx x is the tangent at 0 from lesson 2.3.5, and cos⁡x≈1−x22\cos x \approx 1 - \frac{x^2}{2} is the quadratic copy at the top of the wave.

Far from 0 you need many terms. Here are the partial sums for sin⁡3\sin 3, whose true value is 0.14112.

degree135791113
partial sum3−1.5-1.50.5250.0910710.1453120.1408750.141131

The terms 3kk!\frac{3^k}{k!} first grow, to 4.5 at k=3k = 3 and k=4k = 4, and only then shrink as k!k! wins. The partial sums swing wildly before they settle.

ln⁡(1+x)\ln(1 + x) and the geometric series

The derivatives of ln⁡(1+x)\ln(1 + x) are 11+x\frac{1}{1 + x}, −1(1+x)2-\frac{1}{(1 + x)^2}, 2(1+x)3\frac{2}{(1 + x)^3}, −6(1+x)4-\frac{6}{(1 + x)^4}, by the rules of lessons 2.3.1 and 2.3.4. At 0 they are 1, −1-1, 2, −6-6. Divided by 1!,2!,3!,4!1!, 2!, 3!, 4!, they give the coefficients 1, −12-\frac{1}{2}, 13\frac{1}{3}, −14-\frac{1}{4}.

For 11−x\frac{1}{1 - x} the kk-th derivative at 0 is k!k!, so every coefficient is 1. Its Taylor series is the geometric series of lesson 1.5.3, with first term 1 and ratio xx.

Rule: Series for ln(1 + x) and 1/(1 − x)

ln⁡(1+x)=x−x22+x33−⋯for −1<x≤111−x=1+x+x2+⋯for −1<x<1\begin{gathered} \ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots \\ \text{for } -1 < x \le 1 \\[6pt] \frac{1}{1 - x} = 1 + x + x^2 + \cdots \\ \text{for } -1 < x < 1 \end{gathered}

The bottoms are kk, not k!k!, for ln⁡(1+x)\ln(1 + x), so its terms shrink slowly. Neither series works beyond ∣x∣=1|x| = 1; a later section shows what happens there.

Case study 1.4.7 used ln⁡(1+R)≈R−R22\ln(1 + R) \approx R - \frac{R^2}{2} for small returns RR: these are the first two terms. At R=0.05R = 0.05, ln⁡1.05=0.04879\ln 1.05 = 0.04879 against 0.048750.04875.

Try it

sp.series(f, x, 0, 7) gives the Taylor series about 0 up to x6x^6. O(x**7) stands for the terms from x7x^7 on.

The loop adds up the series for ee to degrees 2 to 6 and 10, with the gap to ee. The last line prints the two numbers for ln⁡1.05\ln 1.05.

⌘/Ctrl + Enter runs the cell

How big is the error?

The first left-out term

Lesson 2.7.1 found that near aa the error of pnp_n is about C(x−a)n+1C(x - a)^{n+1}. The constant is the next coefficient, f(n+1)(a)(n+1)!\frac{f^{(n+1)}(a)}{(n+1)!}.

So the first term you leave out is an estimate of the error. If its coefficient is 0, as half of sine's are, use the next term that is not 0.

approximationerrorfirst left-out term
e0.5≈1+0.5+0.522+0.536e^{0.5} \approx 1 + 0.5 + \frac{0.5^2}{2} + \frac{0.5^3}{6}0.002890.5424=0.0026\frac{0.5^4}{24} = 0.0026
sin⁡0.5≈0.5−0.536\sin 0.5 \approx 0.5 - \frac{0.5^3}{6}0.0002590.55120=0.00026\frac{0.5^5}{120} = 0.00026
ln⁡1.05≈0.05−0.0522\ln 1.05 \approx 0.05 - \frac{0.05^2}{2}0.00004020.0533=0.0000417\frac{0.05^3}{3} = 0.0000417

The estimate is close, but it is not a promise: for e0.5e^{0.5} the true error is larger than the estimate.

A bound you can trust

When you need a guarantee, use the remainder bound. This lesson states it without proof.

Rule: Remainder bound

∣f(x)−pn(x)∣≤M ∣x−a∣n+1(n+1)!\lvert f(x) - p_n(x) \rvert \le \frac{M\,\lvert x - a \rvert^{n+1}}{(n+1)!}

MM is the largest size of f(n+1)f^{(n+1)} anywhere between aa and xx. It is the first left-out term with the derivative at its worst, instead of at aa.

For e0.5e^{0.5} with p3p_3, the fourth derivative exe^x is at most e0.5e^{0.5} between 0 and 0.5. So the error is at most e0.5×0.5424=0.0043e^{0.5} \times \frac{0.5^4}{24} = 0.0043, and the true error, 0.00289, is below that.

For sine and cosine every derivative is a sine or cosine, at most 1 in size. So M=1M = 1, and the error is at most ∣x∣n+1(n+1)!\frac{|x|^{n+1}}{(n+1)!}.

How many terms

To get ee within 10−610^{-6}, use the bound with M=e<3M = e < 3: the error after degree nn is below 3(n+1)!\frac{3}{(n + 1)!}. That first drops below 10−610^{-6} at degree 9, where it is 8.3×10−78.3 \times 10^{-7}, so 10 terms are enough. The true error is 3.0×10−73.0 \times 10^{-7}.

The answer depends on xx. For exe^x within a relative error of 10−610^{-6}, you need 10 terms at x=1x = 1, 20 at x=5x = 5, 29 at x=10x = 10 and 46 at x=20x = 20.

The slow series is ln⁡(1+x)\ln(1 + x) at x=1x = 1: ln⁡2=1−12+13−⋯\ln 2 = 1 - \frac{1}{2} + \frac{1}{3} - \cdots. After 10, 100 and 1,000 terms the error is 0.0475, 0.00498 and 0.0005, about 12n\frac{1}{2n}. Six correct decimals would take about a million terms.

A smaller xx fixes that. Since ln⁡2=−ln⁡(1−0.5)\ln 2 = -\ln(1 - 0.5), use the series at x=−0.5x = -0.5: its terms shrink like 0.5k0.5^k, and 20 of them give ln⁡2\ln 2 within 4.4×10−84.4 \times 10^{-8}.

Try it

The first lines print the table's three errors next to the first left-out terms, then the bound for e0.5e^{0.5}.

The fourth line is the bound 310!\frac{3}{10!} for ee at degree 9, then the true error. terms_for adds terms of the series for exe^x until the relative error is below 10−610^{-6}. The last lines print the slow and the fast way to ln⁡2\ln 2.

⌘/Ctrl + Enter runs the cell

Where a series stops working

The series for exe^x, sin⁡x\sin x and cos⁡x\cos x work for every xx. The other two do not.

ln⁡(1+x)\ln(1 + x) at x=1.5x = 1.5. The function is fine there: ln⁡2.5=0.9163\ln 2.5 = 0.9163. But the terms 1.5kk\frac{1.5^k}{k} grow, so the partial sums swing ever wider.

terms12345102030
partial sum1.50.3751.50.23441.7531−2.4031-2.4031−96.8286-96.8286−3782.6561-3782.6561

Terms that do not shrink to 0 mean the series diverges (lesson 1.5.3). At x=−1x = -1 it is −(1+12+13+⋯ )-\left(1 + \frac{1}{2} + \frac{1}{3} + \cdots\right), minus the harmonic series of lesson 1.5.3, which has no sum either. That matches ln⁡0\ln 0, which does not exist.

11−x\frac{1}{1 - x} at x=2x = 2. The series is 1+2+4+⋯1 + 2 + 4 + \cdots, whose partial sums grow without end, while 11−2=−1\frac{1}{1 - 2} = -1. At x=−1x = -1 it is 1−1+1−⋯1 - 1 + 1 - \cdots, which bounces, while 11−(−1)=12\frac{1}{1 - (-1)} = \frac{1}{2}. Lesson 1.5.3 met both.

Rule: Radius of convergence

converges for ∣x−a∣<Rdiverges for ∣x−a∣>R\begin{gathered} \text{converges for } \lvert x - a \rvert < R \\ \text{diverges for } \lvert x - a \rvert > R \end{gathered}

Every Taylor series has such a distance RR. For ln⁡(1+x)\ln(1 + x) and 11−x\frac{1}{1 - x}, R=1R = 1; for exe^x, sin⁡x\sin x and cos⁡x\cos x there is no limit. At ∣x−a∣=R|x - a| = R itself, check each end.

The trouble at one end limits the other. ln⁡(1+x)\ln(1 + x) breaks at x=−1x = -1, one unit from 0, so its series fails beyond 1 too, where the function is fine.

Near ∣x∣=R|x| = R the series still converges, but slowly: ln⁡2\ln 2 took a million terms, and lesson 1.5.3's 1+0.9+0.81+⋯1 + 0.9 + 0.81 + \cdots needed 66 terms to come within 0.01 of its sum. A Taylor polynomial is still a good copy near 0; it is adding more terms far out that fails.

More terms carry the copy of sin⁡x\sin x further out, without limit. The copies of ln⁡(1+x)\ln(1 + x) hug the curve only for ∣x∣≤1|x| \le 1; beyond 1, more terms make them worse.

Try both sides of the edge. With x=0.5x = 0.5, raise the degree nn and watch the error shrink. Then set x=1.5x = 1.5: every extra term makes the error larger.

Explore

Raise the degree and watch the polynomial hug the curve further from its centre. Move the centre, then the point, and compare the error with the first term left out.

−10123−202

y = ln(1 + x)its Taylor polynomial p5The large dot is the centre; the dashed line at x is the error.The dotted line marks x = −1, where the function breaks.

Polynomial
p5(x)=x−x22+x33−x44+x55p_{5}(x) = x - \dfrac{x^{2}}{2} + \dfrac{x^{3}}{3} - \dfrac{x^{4}}{4} + \dfrac{x^{5}}{5}
At x = 0.5
ln⁡(1+x)\ln(1 + x) = 0.40547, p5(x)p_{5}(x) = 0.40729
Error
−0.00183
First term left out
−0.0026
Reach
x is within 1 of the centre, the distance to the break at x = −1: more terms shrink the error.

Try it

ln1p_series adds the first n terms of the series for ln⁡(1+x)\ln(1 + x). At 1.5 the partial sums run away; at −1-1 they sink like minus the harmonic sums.

The last lines add 20 terms of the geometric series at 2 and at −1-1.

⌘/Ctrl + Enter runs the cell

Two series at once: (1+rn)n\left(1 + \frac{r}{n}\right)^n against ere^r

Case study 2.1.5 found that er−(1+rn)ne^r - \left(1 + \frac{r}{n}\right)^n is about r2er2n\frac{r^2 e^r}{2n}, which is 0.0013141n\frac{0.0013141}{n} at r=0.05r = 0.05. The series for ln⁡(1+x)\ln(1 + x) and exe^x show where that comes from.

  1. 1
    (1+rn)n=e nln⁡(1+r/n)\left(1 + \frac{r}{n}\right)^n = e^{\,n \ln(1 + r/n)}
  2. 2
    nln⁡(1+rn)=r−r22n+r33n2−⋯\begin{gathered} n \ln\left(1 + \frac{r}{n}\right) \\ = r - \frac{r^2}{2n} + \frac{r^3}{3n^2} - \cdots \end{gathered}
  3. 3
    (1+rn)n=ereu≈er(1−r22n)\begin{gathered} \left(1 + \frac{r}{n}\right)^n = e^r e^u \\ \approx e^r\left(1 - \frac{r^2}{2n}\right) \end{gathered}

So the gap er−(1+rn)ne^r - \left(1 + \frac{r}{n}\right)^n is about er×r22ne^r \times \frac{r^2}{2n}. At r=0.05r = 0.05, r2er2=0.0013141\frac{r^2 e^r}{2} = 0.0013141, the number the table of case study 2.1.5 settled on.

Try it

The first line checks step 2 for n=12n = 12: nln⁡(1+rn)n\ln\left(1 + \frac{r}{n}\right) against r−r22nr - \frac{r^2}{2n}.

The loop prints the gap times nn next to r2er2\frac{r^2 e^r}{2}, which it approaches as nn grows.

⌘/Ctrl + Enter runs the cell

Euler's formula from the series

Lesson 1.7.3 checked Euler's formula eiθ=cos⁡θ+isin⁡θe^{i\theta} = \cos\theta + i\sin\theta with numbers. The series give one way to see why it holds for every angle θ\theta, in radians.

Put x=iθx = i\theta into the series for exe^x. The powers of ii go round a cycle of four, 1,i,−1,−i1, i, -1, -i (lesson 1.7.2):

eiθ=1+iθ−θ22!−iθ33!+θ44!+iθ55!−⋯\begin{gathered} e^{i\theta} = 1 + i\theta - \frac{\theta^2}{2!} - \frac{i\theta^3}{3!} \\ + \frac{\theta^4}{4!} + \frac{i\theta^5}{5!} - \cdots \end{gathered}

Sort the terms. The real ones, 1−θ22!+θ44!−⋯1 - \frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \cdots, are the series for cos⁡θ\cos\theta. The others are ii times θ−θ33!+θ55!−⋯\theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!} - \cdots, the series for sin⁡θ\sin\theta.

So eiθ=cos⁡θ+isin⁡θe^{i\theta} = \cos\theta + i\sin\theta. This takes on trust that the series for exe^x works for complex xx as well; all three series work for every input.

Try it

The cell adds 25 terms of ∑(iθ)kk!\sum \frac{(i\theta)^k}{k!}, with 1j for ii, at θ=1\theta = 1 and θ=π\theta = \pi. It compares each sum with cmath.exp and with cos⁡θ+isin⁡θ\cos\theta + i\sin\theta.

tidy rounds both parts to 6 places, as in lesson 1.7.3.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. Radians for sine and cosine. The series x−x36+⋯x - \frac{x^3}{6} + \cdots needs xx in radians, as the derivatives of lesson 2.3.5 do.
  2. Which signs alternate. Sine, cosine and ln⁡(1+x)\ln(1 + x) alternate; exe^x and 11−x\frac{1}{1 - x} do not.
  3. kk, not k!k!, under ln⁡(1+x)\ln(1 + x). Its terms are xkk\frac{x^k}{k}, with a minus sign on the even ones.
  4. A series outside its range gives nonsense. The series for ln⁡(1+x)\ln(1 + x) at x=1.5x = 1.5 and for 11−x\frac{1}{1 - x} at x=2x = 2 diverge, though both functions have values there.
  5. The first left-out term is an estimate, not a guarantee. For a guarantee, use the remainder bound.
  6. More terms for larger ∣x∣|x|. Ten terms give ee within 10−610^{-6}; e20e^{20} needs 46 for the same relative accuracy.

Standard series and the size of the error

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

  • A Taylor series is the Taylor polynomial with n→∞n \to \infty; it equals f(x)f(x) where the partial sums settle on f(x)f(x).
  • ex=∑xkk!e^x = \sum \frac{x^k}{k!}, sin⁡x=x−x33!+⋯\sin x = x - \frac{x^3}{3!} + \cdots and cos⁡x=1−x22!+⋯\cos x = 1 - \frac{x^2}{2!} + \cdots work for every xx (radians for sine and cosine).
  • ln⁡(1+x)=x−x22+x33−⋯\ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots for −1<x≤1-1 < x \le 1; 11−x=1+x+x2+⋯\frac{1}{1 - x} = 1 + x + x^2 + \cdots for ∣x∣<1|x| < 1. Beyond, they diverge.
  • The first left-out term estimates the error; the bound M∣x−a∣n+1(n+1)!\frac{M|x - a|^{n+1}}{(n+1)!} guarantees it. Larger ∣x∣|x| needs more terms.
  • (1+rn)n≈er(1−r22n)\left(1 + \frac{r}{n}\right)^n \approx e^r\left(1 - \frac{r^2}{2n}\right), from the series for ln⁡(1+x)\ln(1 + x) and exe^x. Putting iθi\theta into the series for exe^x gives cos⁡θ+isin⁡θ\cos\theta + i\sin\theta.

Free further reading

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