A Practical Guide to Quantitative Finance Interviews
Contents

3.4 Important Calculus Methods

Taylor’s series

One-dimensional Taylor’s series expands function f(x)f(x) as the sum of a series using the derivatives at a point x=x0x=x_0:

f(x)=f(x0)+f′(x0)(x−x0)+f′′(x0)2!(x−x0)2+⋯+f(n)(x0)n!(x−x0)n+⋯f(x)=f(x_0)+f'(x_0)(x-x_0)+\frac{f''(x_0)}{2!}(x-x_0)^2+\cdots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n+\cdots 42

If x0=0x_0=0, f(x)=f(0)+f′(0)x+f′′(0)2!x2+⋯+f(n)(0)n!xn+⋯\displaystyle f(x)=f(0)+f'(0)x+\frac{f''(0)}{2!}x^2+\cdots+\frac{f^{(n)}(0)}{n!}x^n+\cdots

Taylor’s series are often used to represent functions in power series terms. For example, Taylor’s series for three common transcendental functions, exe^x, sin⁡x\sin x and cos⁡x\cos x, at x0=0x_0=0 are

ex=∑n=0∞1n!=1+x1!+x22!+x33!+⋯ ,sin⁡x=∑n=0∞(−1)nx2n+1(2n+1)!=x−x33!+x55!−x77!+⋯ ,cos⁡x=∑n=0∞(−1)nx2n(2n)!=1−x22!+x44!−x66!+⋯ .\begin{aligned} e^x&=\sum_{n=0}^{\infty}\frac{1}{n!}=1+\frac{x}{1!}+\frac{x^2}{2!}+\frac{x^3}{3!}+\cdots,\\ \sin x&=\sum_{n=0}^{\infty}\frac{(-1)^n x^{2n+1}}{(2n+1)!}=x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+\cdots,\\ \cos x&=\sum_{n=0}^{\infty}\frac{(-1)^n x^{2n}}{(2n)!}=1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\cdots. \end{aligned}

The Taylor’s series can also be expressed as the sum of the nth-degree Taylor polynomial Tn(x)=f(x0)+f′(x0)(x−x0)+f′′(x0)2!(x−x0)2+⋯+f(n)(x0)n!(x−x0)n\displaystyle T_n(x)=f(x_0)+f'(x_0)(x-x_0)+\frac{f''(x_0)}{2!}(x-x_0)^2+\cdots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n and a remainder Rn(x)R_n(x): f(x)=Tn(x)+Rn(x)f(x)=T_n(x)+R_n(x).

For some x~\tilde{x} between x0x_0 and xx, Rn(x)=f(n+1)(x~)(n+1)!∣x−x0∣n+1\displaystyle R_n(x)=\frac{f^{(n+1)}(\tilde{x})}{(n+1)!}|x-x_0|^{n+1}. Let MM be the maximum of ∣f(n+1)(x~)∣|f^{(n+1)}(\tilde{x})| for all x~\tilde{x} between x0x_0 and xx, we get constraint ∣Rn(x)∣≤M×∣x−x0∣n+1(n+1)!\displaystyle |R_n(x)|\le\frac{M\times|x-x_0|^{n+1}}{(n+1)!}.

A. What is iii^i?

Solution: The solution to this problem uses Euler’s formula, eiθ=cos⁡θ+isin⁡θe^{i\theta}=\cos\theta+i\sin\theta, which can be proven using Taylor’s series. Let’s look at the proof. Applying Taylor’s series to eiθe^{i\theta}, cos⁡θ\cos\theta and sin⁡θ\sin\theta, we have

eiθ=1+iθ1!+(iθ)22!+(iθ)33!+(iθ)44!+⋯=1+iθ1!−θ22!−iθ33!+θ44!+iθ55!+⋯\begin{aligned} e^{i\theta}&=1+\frac{i\theta}{1!}+\frac{(i\theta)^2}{2!}+\frac{(i\theta)^3}{3!}+\frac{(i\theta)^4}{4!}+\cdots\\ &=1+i\frac{\theta}{1!}-\frac{\theta^2}{2!}-i\frac{\theta^3}{3!}+\frac{\theta^4}{4!}+i\frac{\theta^5}{5!}+\cdots \end{aligned} cos⁡θ=1−θ22!+θ44!−θ66!+⋯\cos\theta=1-\frac{\theta^2}{2!}+\frac{\theta^4}{4!}-\frac{\theta^6}{6!}+\cdots sin⁡θ=θ−θ33!+θ55!−θ77!+⋯⇒isin⁡θ=iθ1!−iθ33!+iθ55!−iθ77!+⋯\sin\theta=\theta-\frac{\theta^3}{3!}+\frac{\theta^5}{5!}-\frac{\theta^7}{7!}+\cdots\Rightarrow i\sin\theta=i\frac{\theta}{1!}-i\frac{\theta^3}{3!}+i\frac{\theta^5}{5!}-i\frac{\theta^7}{7!}+\cdots 43

Combining these three series, it is apparent that eiθ=cos⁡θ+isin⁡θe^{i\theta}=\cos\theta+i\sin\theta.

When θ=π\theta=\pi, the equation becomes eiπ=cos⁡π+isin⁡π=−1e^{i\pi}=\cos\pi+i\sin\pi=-1. When θ=π/2\theta=\pi/2, the equation becomes eiπ/2=cos⁡(π/2)+isin⁡(π/2)=ie^{i\pi/2}=\cos(\pi/2)+i\sin(\pi/2)=i.3 So ln⁡i=ln⁡(eiπ/2)=iπ/2\ln i=\ln(e^{i\pi/2})=i\pi/2.

Hence, ln⁡(ii)=iln⁡i=i(iπ/2)=−π/2⇒ii=e−π/2\ln(i^i)=i\ln i=i(i\pi/2)=-\pi/2\Rightarrow i^i=e^{-\pi/2}.

B. Prove (1+x)n≥1+nx(1+x)^n\ge 1+nx for all x>−1x>-1 and for all integers n≥2n\ge 2.

Solution: Let f(x)=(1+x)nf(x)=(1+x)^n. It is clear that 1+nx1+nx is the first two terms in the Taylor’s series of f(x)f(x) with x0=0x_0=0. So we can consider solving this problem using Taylor’s series.

For x0=0x_0=0 we have (1+x)n=1(1+x)^n=1 for ∀n≥2\forall n\ge 2. The first and secondary derivatives of f(x)f(x) are f′(x)=n(1+x)n−1f'(x)=n(1+x)^{n-1} and f′′(x)=n(n−1)(1+x)n−2f''(x)=n(n-1)(1+x)^{n-2}. Applying Taylor’s series, we have

f(x)=f(x0)+f′(x0)(x−x0)+f′′(x~)2!(x−x0)2=f(0)+f′(0)x+f′′(x~)2!x2,=1+nx+n(n−1)(1+x~)n−2x2\begin{aligned} f(x)&=f(x_0)+f'(x_0)(x-x_0)+\frac{f''(\tilde{x})}{2!}(x-x_0)^2\\ &=f(0)+f'(0)x+\frac{f''(\tilde{x})}{2!}x^2,\\ &=1+nx+n(n-1)(1+\tilde{x})^{n-2}x^2 \end{aligned}

where x≤x~≤0x\le\tilde{x}\le 0 if x<0x<0 and x≥x~≥0x\ge\tilde{x}\ge 0 if x>0x>0.

Since x>−1x>-1 and n≥2n\ge 2, we have n>0n>0, (n−1)>0(n-1)>0, (1+x~)n−2>0(1+\tilde{x})^{n-2}>0, x2≥0x^2\ge 0.

Hence, n(n−1)(1+x~)n−2x2≥0n(n-1)(1+\tilde{x})^{n-2}x^2\ge 0 and f(x)=(1+x)n>1+nxf(x)=(1+x)^n>1+nx.

If Taylor’s series does not jump to your mind, the condition that nn is an integer may give you the hint that you can try the induction method. We can rephrase the problem as: for every integer n≥2n\ge 2, prove (1+x)n≥1+nx(1+x)^n\ge 1+nx for x>−1x>-1.

The base case: show (1+x)n≥1+nx,∀x>−1(1+x)^n\ge 1+nx,\forall x>-1 when n=2n=2, which can be easily proven since (1+x)2≥1+2x+x2≥1+2x, ∀x>−1(1+x)^2\ge 1+2x+x^2\ge 1+2x,\ \forall x>-1.

The induction step: show that if (1+x)n≥1+nx,∀x>−1(1+x)^n\ge 1+nx,\forall x>-1 when n=kn=k, the same statement holds for n=k+1n=k+1: (1+x)k+1≥1+(k+1)x,∀x>−1(1+x)^{k+1}\ge 1+(k+1)x,\forall x>-1. This step is straightforward as well.

44 (1+x)k+1=(1+x)k(1+x)≥(1+kx)(1+x)=1+(k+1)x+kx2,∀x>−1≥1+(k+1)x\begin{aligned} (1+x)^{k+1}&=(1+x)^k(1+x)\\ &\ge(1+kx)(1+x)=1+(k+1)x+kx^2,\quad\forall x>-1\\ &\ge 1+(k+1)x \end{aligned}

So the statement holds for all integers n≥2n\ge 2 when x>−1x>-1.

Newton’s method

Newton’s method, also known as the Newton-Raphson method or the Newton-Fourier method, is an iterative process for solving the equation f(x)=0f(x)=0. It begins with an initial value x0x_0 and applies the iterative step xn+1=xn−f(xn)f′(xn)\displaystyle x_{n+1}=x_n-\frac{f(x_n)}{f'(x_n)} to solve f(x)=0f(x)=0 if x1,x2,⋯x_1,x_2,\cdots converge.4

Convergence of Newton’s method is not guaranteed, especially when the starting point is far away from the correct solution. For Newton’s method to converge, it is often necessary that the initial point is sufficiently close to the root; f(x)f(x) must be differentiable around the root. When it does converge, the convergence rate is quadratic, which means ∣xn+1−xf∣(xn−xf)2≤δ<1\displaystyle\frac{|x_{n+1}-x_f|}{(x_n-x_f)^2}\le\delta<1, where xfx_f is the solution to f(x)=0f(x)=0.

A. Solve x2=37x^2=37 to the third digit.

Solution: Let f(x)=x2−37f(x)=x^2-37, the original problem is equivalent to solving f(x)=0f(x)=0. x0=6x_0=6 is a natural initial guess. Applying Newton’s method, we have

x1=x0−f(x0)f′(x0)=x0−x02−372x0=6−36−372×6=6.083.x_1=x_0-\frac{f(x_0)}{f'(x_0)}=x_0-\frac{x_0^2-37}{2x_0}=6-\frac{36-37}{2\times 6}=6.083.

(6.0832=37.002896.083^2=37.00289, which is very close to 37.)

If you do not remember Newton’s method, you can directly apply Taylor’s series for function f(x)=xf(x)=\sqrt{x} with f′(x)=12x−1/2f'(x)=\frac12 x^{-1/2}:

f(37)≈f(36)+f′(36)(37−36)=6+1/12=6.083.f(37)\approx f(36)+f'(36)(37-36)=6+1/12=6.083. 45

Alternatively, we can use algebra since it is obvious that the solution should be slightly higher than 6. We have (6+y)2=37⇒y2+12y−1=0(6+y)^2=37\Rightarrow y^2+12y-1=0. If we ignore the y2y^2 term, which is small, then y=0.083y=0.083 and x=6+y=6.083x=6+y=6.083.

B. Could you explain some root-finding algorithms to solve f(x)=0f(x)=0? Assume f(x)f(x) is a differentiable function.

Solution: Besides Newton’s method, the bisection method and the secant method are two alternative methods for root-finding.5

Bisection method is an intuitive root-finding algorithm. It starts with two initial values a0a_0 and b0b_0 such that f(a0)<0f(a_0)<0 and f(b0)>0f(b_0)>0. Since f(x)f(x) is differentiable, there must be an xx between a0a_0 and b0b_0 that makes f(x)=0f(x)=0. At each step, we check the sign of f((an+bn)/2)f((a_n+b_n)/2). If f((an+bn)/2)<0f((a_n+b_n)/2)<0, we set bn+1=bnb_{n+1}=b_n and an+1=(an+bn)/2a_{n+1}=(a_n+b_n)/2; If f((an+bn)/2)>0f((a_n+b_n)/2)>0, we set an+1=ana_{n+1}=a_n and bn+1=(an+bn)/2b_{n+1}=(a_n+b_n)/2; If f((an+bn)/2)=0f((a_n+b_n)/2)=0, or its absolute value is within allowable error, the iteration stops and x=(an+bn)/2x=(a_n+b_n)/2. The bisection method converges linearly, xn+1−xfxn−xf≤δ<1\displaystyle\frac{x_{n+1}-x_f}{x_n-x_f}\le\delta<1, which means it is slower than Newton’s method. But once you find an a0/b0a_0/b_0 pair, convergence is guaranteed.

Secant method starts with two initial values x0,x1x_0,x_1 and applies the iterative step xn+1=xn−xn−xn−1f(xn)−f(xn−1)f(xn)\displaystyle x_{n+1}=x_n-\frac{x_n-x_{n-1}}{f(x_n)-f(x_{n-1})}f(x_n). It replaces the f′(xn)f'(x_n) in Newton’s method with a linear approximation f(xn)−f(xn−1)xn−xn−1\displaystyle\frac{f(x_n)-f(x_{n-1})}{x_n-x_{n-1}}. Compared with Newton’s method, it does not require the calculation of derivative f′(xn)f'(x_n), which makes it valuable if f′(x)f'(x) is difficult to calculate. Its convergence rate is (1+5)/2(1+\sqrt{5})/2, which makes it faster than the bisection method but slower than Newton’s method. Similar to Newton’s method, convergence is not guaranteed if initial values are not close to the root.

Lagrange multipliers

The method of Lagrange multipliers is a common technique used to find local maximums/minimums of a multivariate function with one or more constraints.6

46

Let f(x1,x2,⋯ ,xn)f(x_1,x_2,\cdots,x_n) be a function of nn variables x=(x1,x2,⋯ ,xn)x=(x_1,x_2,\cdots,x_n) with gradient vector ∇f(x)=⟨∂f∂x1,∂f∂x2,⋯ ,∂f∂xn⟩\displaystyle\nabla f(x)=\left\langle\frac{\partial f}{\partial x_1},\frac{\partial f}{\partial x_2},\cdots,\frac{\partial f}{\partial x_n}\right\rangle. The necessary condition for maximizing or minimizing f(x)f(x) subject to a set of kk constraints

g1(x1,x2,⋯ ,xn)=0,g2(x1,x2,⋯ ,xn)=0,⋯ ,gk(x1,x2,⋯ ,xn)=0g_1(x_1,x_2,\cdots,x_n)=0,\quad g_2(x_1,x_2,\cdots,x_n)=0,\quad\cdots,\quad g_k(x_1,x_2,\cdots,x_n)=0

is that ∇f(x)+λ1∇g1(x)+λ2∇g2(x)+⋯+λk∇gk(x)=0\nabla f(x)+\lambda_1\nabla g_1(x)+\lambda_2\nabla g_2(x)+\cdots+\lambda_k\nabla g_k(x)=0, where λ1,⋯ ,λk\lambda_1,\cdots,\lambda_k are called the Lagrange multipliers.

What is the distance from the origin to the plane 2x+3y+4z=122x+3y+4z=12?

Solution: The distance (DD) from the origin to a plane is the minimum distance between the origin and points on the plane. Mathematically, the problem can be expressed as

min⁡ D2=f(x,y,z)=x2+y2+z2s.t.g(x,y,z)=2x+3y+4z−12=0\begin{aligned}\min\ D^2&=f(x,y,z)=x^2+y^2+z^2\\\text{s.t.}\quad g(x,y,z)&=2x+3y+4z-12=0\end{aligned}

Applying the Lagrange multipliers, we have

∂f∂x+λ∂f∂x=2x+2λ=0∂f∂y+λ∂f∂y=2y+3λ=0∂f∂z+λ∂f∂z=2x+4λ=02x+3y+4z−12=0}⇒{λ=−24/29x=24/29y=36/29z=48/29\left.\begin{aligned}\frac{\partial f}{\partial x}+\lambda\frac{\partial f}{\partial x}&=2x+2\lambda=0\\\frac{\partial f}{\partial y}+\lambda\frac{\partial f}{\partial y}&=2y+3\lambda=0\\\frac{\partial f}{\partial z}+\lambda\frac{\partial f}{\partial z}&=2x+4\lambda=0\\2x+3y+4z-12&=0\end{aligned}\right\}\Rightarrow\begin{cases}\lambda=-24/29\\x=24/29\\y=36/29\\z=48/29\end{cases} ⇒D=(2429)2+(3629)2+(4829)2=1229\Rightarrow D=\sqrt{\left(\frac{24}{29}\right)^2+\left(\frac{36}{29}\right)^2+\left(\frac{48}{29}\right)^2}=\frac{12}{\sqrt{29}}

In general, for a plane with equation ax+by+cz=dax+by+cz=d, the distance to the origin is D=∣d∣a2+b2+c2\displaystyle D=\frac{|d|}{\sqrt{a^2+b^2+c^2}}.