SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 4.1.1 Functions of two variables: surfaces and level curvesConcept · 30 min
      2. 4.1.2 Partial derivativesConcept · 35 min
      3. 4.1.3 Practice set: partial derivativesPractice set · 20 min
      4. 4.1.4 Case study: the Greeks as partial derivativesCase study · 35 min

Level 4, Multivariable calculus and optimisation 4.1 Functions of several variables Lesson 2 of 4

ConceptLesson 4.1.2 in Level 4, Multivariable calculus and optimisation. About 35 minutes.

Partial derivatives

The slope of a slice

Lesson 4.1.1 cut the bowl f(x,y)=x2+2y2f(x, y) = x^2 + 2y^2 into slices. Fix y=1y = 1 and the slice is x2+2x^2 + 2, a function of xx alone, so it has a slope. That slope is a partial derivative: the rate at which ff changes as xx moves, with yy held fixed.

Take the point (1,1)(1, 1), where f=3f = 3. Move xx by a gap hh and keep yy at 1. Then do the same in the other direction: keep xx at 1 and move yy.

gap hh±0.1\pm 0.1±0.01\pm 0.01±0.001\pm 0.001
chord slope, xx moving2.1, 1.92.01, 1.992.001, 1.999
chord slope, yy moving4.2, 3.84.02, 3.984.002, 3.998

From both sides the first row settles on 2 and the second on 4. So at (1,1)(1, 1) the surface rises twice as fast in the yy direction as in the xx direction.

The algebra agrees. With y=1y = 1 fixed, the chord slope is (1+h)2+2−3h=2+h\frac{(1 + h)^2 + 2 - 3}{h} = 2 + h, which tends to 2. With x=1x = 1 fixed, it is 1+2(1+h)2−3h=4+2h\frac{1 + 2(1 + h)^2 - 3}{h} = 4 + 2h, which tends to 4.

Rule: Partial derivatives

∂f∂x(a,b)=lim⁡h→0f(a+h,b)−f(a,b)h∂f∂y(a,b)=lim⁡h→0f(a,b+h)−f(a,b)h\begin{gathered} \frac{\partial f}{\partial x}(a, b) = \lim_{h \to 0} \frac{f(a + h, b) - f(a, b)}{h} \\[6pt] \frac{\partial f}{\partial y}(a, b) = \lim_{h \to 0} \frac{f(a, b + h) - f(a, b)}{h} \end{gathered}

Lesson 2.2.2's derivative, taken along one input while the other stays fixed. ∂f∂x\frac{\partial f}{\partial x} is the slope of the slice y=by = b at x=ax = a; ∂f∂y\frac{\partial f}{\partial y} is the slope of the slice x=ax = a at y=by = b.

The two slices of x2+2y2x^2 + 2y^2 through (1,1)(1, 1), with their tangents at the point. The slope of each tangent is a partial derivative: 2 in the xx direction, 4 in the yy direction.

Try it on the explorer. The point starts at (2, 1) on the bowl x2+2y2x^2 + 2y^2, where the slice along xx has slope 4. Slide the point along the dashed line and watch the slope change; then slice along yy instead, and try the other functions.

Explore

Hold y fixed and f becomes a function of x alone: a slice through the surface, graphed below. Its slope at the point is the partial derivative ∂f/∂x. Move the point, or slice along y instead to read ∂f/∂y.

−202−2−1012

The slice y = 1: f(x, 1) against x, with its tangent at the point

−202510
Point
(2, 1), f = 6
Partial derivatives
∂f/∂x = 4 (the slope of the slice along x), ∂f/∂y = 4 (along y)

Notation

The curly ∂\partial is read "partial", so ∂f∂x\frac{\partial f}{\partial x} is "partial f by partial x". It replaces the dd of dfdx\frac{df}{dx} to warn that ff has other inputs, held fixed. A shorter name is fxf_x, with the input that moves written below.

Both name a new function of xx and yy. For the bowl, fx=2xf_x = 2x and fy=4yf_y = 4y at every point. At one point, write fx(1,1)=2f_x(1, 1) = 2, giving both coordinates.

Try it

The cell repeats the table: chord slopes at (1,1)(1, 1) from both sides. First xx moves with yy fixed at 1, then the other way round.

round(…, 6) hides rounding noise in the last digits.

⌘/Ctrl + Enter runs the cell

The rules of Level 2 still work

To find fxf_x, treat yy as a fixed number, such as 5, and differentiate in xx by the usual rules. To find fyf_y, do the reverse. Nothing new is needed.

A polynomial. Take f(x,y)=x2y+3y2f(x, y) = x^2y + 3y^2. In x2yx^2y the yy is a constant factor, so its xx-derivative is 2x⋅y2x \cdot y (lesson 2.3.1). The term 3y23y^2 does not contain xx at all, so it is a constant and its xx-derivative is 0.

fx=2xyfy=x2+6y\begin{gathered} f_x = 2xy \\[4pt] f_y = x^2 + 6y \end{gathered}

In fyf_y, the x2x^2 is a constant factor of yy, which has slope 1. At (2,1)(2, 1) the function is 7, with fx=4f_x = 4 and fy=10f_y = 10.

The chain rule. For g(x,y)=exyg(x, y) = e^{xy}, the inside is xyxy. Its slope in xx is yy, so gx=yexyg_x = ye^{xy} (lessons 2.3.3 and 2.3.4).

In the same way gy=xexyg_y = xe^{xy}. At (1,2)(1, 2): gx=2e2≈14.7781g_x = 2e^2 \approx 14.7781 and gy=e2≈7.3891g_y = e^2 \approx 7.3891.

The quotient rule, or a power. For q(x,y)=xyq(x, y) = \frac{x}{y}, the 1y\frac{1}{y} is a constant factor in xx, so qx=1yq_x = \frac{1}{y}. In yy, write q=x y−1q = x\,y^{-1}: then qy=−xy2q_y = -\frac{x}{y^2}. At (3,2)(3, 2): qx=12q_x = \frac{1}{2} and qy=−34q_y = -\frac{3}{4}.

Rule: Computing a partial derivative

fx: treat y as a constantfy: treat x as a constant\begin{gathered} f_x: \text{ treat } y \text{ as a constant} \\[4pt] f_y: \text{ treat } x \text{ as a constant} \end{gathered}

Then use the rules of lessons 2.3.1 to 2.3.5. A term without the moving variable has derivative 0; a factor without it stays as a factor.

Try it

sp.diff(f, x) is the partial derivative in xx: SymPy holds every other symbol fixed. Each first line prints ff, fxf_x, fyf_y, and the exact values of fxf_x and fyf_y at the point.

SymPy keeps e2e^2 exact as exp(2). The second line gives ff, fxf_x and fyf_y at the point as decimals.

⌘/Ctrl + Enter runs the cell

Signs, units and where it breaks

The sign of fxf_x says what happens when xx grows and yy stays put. Positive means ff rises, negative means it falls, and zero means the slice is flat there. The other partial can tell a different story at the same point.

For the saddle x2−y2x^2 - y^2 of lesson 4.1.1, fx=2xf_x = 2x and fy=−2yf_y = -2y. At (1,1)(1, 1), fx=2f_x = 2 and fy=−2f_y = -2: uphill along xx, downhill along yy. At (0,0)(0, 0) both are 0, and for the plane 6−2x−3y6 - 2x - 3y they are −2-2 and −3-3 everywhere.

Units

A partial derivative is in output units per unit of the input that moves. A tin can of radius rr cm and height ℓ\ell cm holds V=πr2ℓV = \pi r^2\ell cm³. Then ∂V∂r=2πrℓ\frac{\partial V}{\partial r} = 2\pi r\ell is in cm³ per cm of radius, and ∂V∂ℓ=πr2\frac{\partial V}{\partial \ell} = \pi r^2 in cm³ per cm of height.

For r=3r = 3 and ℓ=10\ell = 10, V=282.74V = 282.74 cm³, ∂V∂r=188.5\frac{\partial V}{\partial r} = 188.5 and ∂V∂ℓ=28.27\frac{\partial V}{\partial \ell} = 28.27. Widening the can is far more effective than making it taller: per centimetre, more than six times as many cm³.

Each partial gives a tangent estimate in its own direction, as in lesson 2.2.1. With ℓ\ell fixed at 10, widening rr by 0.1 adds about 188.5×0.1=18.85188.5 \times 0.1 = 18.85 cm³; the true gain is 19.16. With rr fixed at 3, adding 0.1 to ℓ\ell adds 2.83 cm³, exactly, because VV is a straight line in ℓ\ell.

Where a partial derivative does not exist

A partial derivative is a one-variable derivative, so it fails where lesson 2.2.2's did. Take g(x,y)=∣x∣+y2g(x, y) = |x| + y^2 at (0,1)(0, 1).

With yy fixed, the slice ∣x∣+1|x| + 1 has a corner at 0. Its chord slopes are 1 from the right and −1-1 from the left, so gxg_x does not exist there.

The other slice is smooth. With x=0x = 0 fixed, the slice is g(0,y)=y2g(0, y) = y^2, so gy=2y=2g_y = 2y = 2 at (0,1)(0, 1). One partial can exist where the other does not.

Try it

The tin can's volume and its two partials. Then the tangent estimate for widening it by 0.1 cm, and the true gains from widening and from raising it by 0.1 cm.

The last loop takes chord slopes of ∣x∣+y2|x| + y^2 at (0,1)(0, 1): in xx from both sides, and in yy.

⌘/Ctrl + Enter runs the cell

Second partial derivatives

fxf_x and fyf_y are functions of xx and yy too, so each has two partial derivatives of its own. That gives four second partial derivatives:

fxx=(fx)x,fyy=(fy)yfxy=(fx)y,fyx=(fy)x\begin{gathered} f_{xx} = (f_x)_x, \quad f_{yy} = (f_y)_y \\[4pt] f_{xy} = (f_x)_y, \quad f_{yx} = (f_y)_x \end{gathered}

fxxf_{xx} is the second derivative of the slice in xx: it measures how that slice bends (lesson 2.4.2). For the bowl, fxx=2f_{xx} = 2 and fyy=4f_{yy} = 4, so the slices in yy bend twice as sharply.

The mixed partials fxyf_{xy} and fyxf_{yx} are new. fxyf_{xy} says how the slope in xx changes as yy moves.

A worked example

Take f(x,y)=x2y+3y2f(x, y) = x^2y + 3y^2 again, with fx=2xyf_x = 2xy. At x=2x = 2 that slope is 4y4y. Read it off three slices:

slicey=0y = 0y=1y = 1y=2y = 2
f(x,y)f(x, y) as a function of xx0x2+3x^2 + 32x2+122x^2 + 12
its slope at x=2x = 2, fx(2,y)f_x(2, y)048

Each step of 1 in yy adds 4 to the slope. So fxy(2,y)=4f_{xy}(2, y) = 4. Differentiating fx=2xyf_x = 2xy in yy gives the same: fxy=2xf_{xy} = 2x, which is 4 at x=2x = 2.

The slope in xx at x=2x = 2 grows as yy grows: 0, 4 and 8 on the slices y=0y = 0, 1 and 2. Its rate of growth, 4 per unit of yy, is the mixed partial derivative.

Now go the other way: fy=x2+6yf_y = x^2 + 6y, and its xx-derivative is fyx=2xf_{yx} = 2x. The two mixed partials agree. The rest: fxx=2yf_{xx} = 2y and fyy=6f_{yy} = 6, so at (2,1)(2, 1) they are 2 and 6.

Rule: Mixed partials agree

fxy=fyxf_{xy} = f_{yx}

The order of differentiation does not matter when the second partials are continuous, which holds for every function in this course. This lesson states it; the Proof Gym proves it.

So a function of two variables has only three different second partials: fxxf_{xx}, fxyf_{xy} and fyyf_{yy}. Lesson 4.3.1 puts them in a symmetric matrix, the Hessian HH.

Two notations need care. fxyf_{xy} is read left to right: first xx, then yy.

The same thing written with ∂\partial is ∂2f∂y ∂x\frac{\partial^2 f}{\partial y\,\partial x}, read right to left. Since the two agree, the order rarely changes an answer.

Try it

sp.diff(f, x, 2) is fxxf_{xx}, and sp.diff(f, x, y) differentiates in xx, then in yy. Each line prints fxxf_{xx}, fxyf_{xy}, whether fxy−fyxf_{xy} - f_{yx} simplifies to 0, and fyyf_{yy}.

The last line is the table's slope fx(2,y)f_x(2, y) at y=0y = 0, 1 and 2.

⌘/Ctrl + Enter runs the cell

For the bowl the mixed partial is 0: its slope in xx, 2x2x, does not depend on yy. For xyxy it is 1, since the slice y=by = b has slope bb.

Estimating partials by central differences

When ff is a program rather than a formula, estimate each partial by lesson 2.8.1's central difference. Move one input up and down by hh, and keep the other exactly where it was.

Rule: Central differences in two variables

fx≈f(x+h,y)−f(x−h,y)2hfxx≈f(x+h,y)−2f(x,y)+f(x−h,y)h2fxy≈f++−f+−−f−++f−−4h2\begin{gathered} f_x \approx \frac{f(x + h, y) - f(x - h, y)}{2h} \\[6pt] f_{xx} \approx \\ \frac{f(x + h, y) - 2f(x, y) + f(x - h, y)}{h^2} \\[6pt] f_{xy} \approx \frac{f_{++} - f_{+-} - f_{-+} + f_{--}}{4h^2} \end{gathered}

fyf_y and fyyf_{yy} are the same with yy moving. In the last line f+−f_{+-} means f(x+h,y−h)f(x + h, y - h), and so on. It is the central difference in yy of the central difference in xx, from four corner points.

For g=exyg = e^{xy} at (1,2)(1, 2) the true values are gx=2e2≈14.778112g_x = 2e^2 \approx 14.778112 and gxy=(1+xy)exy=3e2≈22.167168g_{xy} = (1 + xy)e^{xy} = 3e^2 \approx 22.167168.

step hh0.10.010.001
estimate of gxg_x14.8768314.77909714.778122
its error9.9×10−29.9 \times 10^{-2}9.9×10−49.9 \times 10^{-4}9.9×10−69.9 \times 10^{-6}
estimate of gxyg_{xy}22.47755722.17024722.167199
its error3.1×10−13.1 \times 10^{-1}3.1×10−33.1 \times 10^{-3}3.1×10−53.1 \times 10^{-5}

Both errors shrink like h2h^2: ten times smaller hh, a hundred times smaller error. The first matches lesson 2.8.1's 16gxxxh2\frac{1}{6}g_{xxx}h^2, with gxxx=y3exy=8e2g_{xxx} = y^3e^{xy} = 8e^2 here.

Rounding sets a floor, as in lesson 2.8.1. For a first partial a step near 10−510^{-5} times the scale of the input works well, and for second partials near 10−410^{-4}. With h=10−8h = 10^{-8} the mixed estimate is ruined by rounding.

Try it

central_x and mixed are the first and last formulas of the rule. Each line of the loop prints the step, the two estimates and their errors.

The last line checks the step sizes: h=10−4h = 10^{-4} gets gxyg_{xy} within 10−510^{-5}, and h=10−8h = 10^{-8} misses by more than 0.001.

⌘/Ctrl + Enter runs the cell

Three or more variables

Nothing changes with more inputs: to differentiate in one, hold all the others fixed. A box with sides xx, yy and zz cm has volume V=xyzV = xyz cm³, with

Vx=yz,Vy=xz,Vz=xyV_x = yz, \quad V_y = xz, \quad V_z = xy

For a box of 2×3×42 \times 3 \times 4 cm, V=24V = 24 and the partials are 12, 8 and 6 cm³ per cm. The shortest side gives the most: adding 0.1 cm to xx adds exactly 12×0.1=1.212 \times 0.1 = 1.2 cm³, since VV is a straight line in xx.

There are now nine second partials: three on the diagonal, such as VxxV_{xx}, and three equal pairs, such as Vxy=Vyx=zV_{xy} = V_{yx} = z. For the box they are 4, 3 and 2 off the diagonal, and Vxx=Vyy=Vzz=0V_{xx} = V_{yy} = V_{zz} = 0.

Try it

The three partials of xyzxyz at (2,3,4)(2, 3, 4), then the table of all nine second partials. Row ii, column jj holds the derivative in the ii-th variable, then the jj-th. The table is symmetric.

The last line is the gain from adding 0.1 cm to xx.

⌘/Ctrl + Enter runs the cell

Case study 4.1.4 treats an option's value as a function of the stock price, the volatility and time. Its sensitivities are partial derivatives. Lesson 4.2.1 puts the first partials together into one vector, the gradient.

Common mistakes

  1. The fixed variable is a number, not a variable. ∂∂x(x2y)=2xy\frac{\partial}{\partial x}(x^2y) = 2xy. Using the product rule as if yy moved gives an extra term that does not belong.
  2. A term without the moving variable vanishes; a factor stays. ∂∂x(y2)=0\frac{\partial}{\partial x}(y^2) = 0, but ∂∂x(xy2)=y2\frac{\partial}{\partial x}(xy^2) = y^2.
  3. A value needs both coordinates. For the bowl fx=2xf_x = 2x does not involve yy, but the point is still (1,1)(1, 1), where fx=2f_x = 2 and fy=4f_y = 4.
  4. Units are per unit of the moving input. ∂V∂r\frac{\partial V}{\partial r} for the can is in cm³ per cm of radius.
  5. One partial can exist where another does not. For ∣x∣+y2|x| + y^2 at (0,1)(0, 1), gy=2g_y = 2 but gxg_x does not exist.
  6. Mind the order in the notation. fxyf_{xy} means xx first; ∂2f∂y ∂x\frac{\partial^2 f}{\partial y\,\partial x} means the same.
  7. In a central difference, move only one input, and keep the other exactly fixed. A mixed partial needs four corner points.

Partial derivatives

0 of 13 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.
  13. 13.
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

  • ∂f∂x\frac{\partial f}{\partial x}, or fxf_x, is the derivative in xx with yy held fixed: the slope of the slice y=by = b. Likewise fyf_y. Units: output per unit of the moving input.
  • Compute it with the rules of Level 2, treating the other variable as a constant. Its sign says whether ff rises as that input grows.
  • A partial derivative fails where a one-variable derivative does, such as at a corner; one partial can exist while another does not.
  • Second partials: fxxf_{xx} and fyyf_{yy} measure the bend of slices; fxyf_{xy} is how the xx-slope changes with yy. For the functions of this course, fxy=fyxf_{xy} = f_{yx}.
  • Central differences estimate partials: move one input by ±h\pm h, keep the others fixed. The mixed partial uses four corner points. Errors shrink like h2h^2 until rounding takes over.
  • With three or more variables, hold all the others fixed.

Free further reading

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