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 5 of 6

Case studyLesson 2.4.5 in Level 2, Single-variable calculus. About 30 minutes.

Case study: convexity and risk aversion

The price curve bends up

A bond pays ctc_t at each time tt, in years. At the yield yy (a decimal: 5% is 0.05), its price is P(y)=∑tct(1+y)−tP(y) = \sum_t c_t(1 + y)^{-t}.

Case study 2.2.4 found the tangent to this curve always below the true price. That is a concave-up curve: P′′(y)>0P''(y) > 0.

Differentiate one payment twice, by the power and chain rules (lessons 2.3.1 and 2.3.3). The first derivative is −t ct(1+y)−t−1-t\,c_t(1 + y)^{-t-1}, as in case study 2.3.7. The second is t(t+1) ct(1+y)−t−2t(t + 1)\,c_t(1 + y)^{-t-2}, positive for every payment, so P′′>0P'' > 0 for any bond with positive payments.

Rule: Convexity

C=1P d2Pdy2=1P∑tt(t+1) ct(1+y)t+2\begin{gathered} C = \frac{1}{P}\,\frac{d^2P}{dy^2} \\[4pt] = \frac{1}{P}\sum_t \frac{t(t + 1)\,c_t}{(1 + y)^{t + 2}} \end{gathered}

The second derivative of the price, per unit of price. Duration D=−1PdPdyD = -\frac{1}{P}\frac{dP}{dy} measures the slope; convexity measures the bend. For the 5-year 4% bond at 5%, C≈24.47C \approx 24.47.

Try it

SymPy differentiates the price formula once for DD and twice for CC. The bond is worth 95.6705, with D=4.40031D = 4.40031 and C=24.4724C = 24.4724.

The second line sums t(t+1)ct1.05t+2\frac{t(t + 1)c_t}{1.05^{t + 2}} over the payments: P′′=2341.2878P'' = 2341.2878, and the same CC.

⌘/Ctrl + Enter runs the cell

Duration plus convexity

Duration alone is the tangent: a straight-line estimate of the price change. Adding a term for the bend gives a parabola that follows the curve much further. Here Δy\Delta y is the change in yield.

Rule: Duration–convexity estimate

ΔPP≈−D Δy+12 C (Δy)2\frac{\Delta P}{P} \approx -D\,\Delta y + \frac{1}{2}\,C\,(\Delta y)^2

The first term is case study 2.2.4's tangent. The second is the correction for the bend; module 2.7 shows where the 12\frac{1}{2} comes from. Because (Δy)2>0(\Delta y)^2 > 0, the correction is positive whichever way the yield moves.

For a 2% rise, −D Δy=−8.8006%-D\,\Delta y = -8.8006\% and 12C(Δy)2=+0.4894%\frac{1}{2}C(\Delta y)^2 = +0.4894\%. The estimate is a fall of 8.3112%, to 87.7192; the true fall is 8.3318%, to 87.6994. For a 2% fall the same correction is added again: a rise of 9.2900% against a true 9.3124%.

yield movetrue priceduration onlywith convexity
−3%-3\%109.4269108.2999109.3535
−2%-2\%104.5797104.0901104.5584
−1%-1\%100.000099.880399.9974
+1%+1\%91.575391.460791.5778
+2%+2\%87.699487.250987.7192
+3%+3\%84.029283.041184.0947

Duration alone is off by 0.45 for a 2% rise; with convexity, by 0.02. Doubling the move roughly quadruples the duration error, as for any tangent. The convexity estimate's error grows about eight times, from 0.0025 to 0.0198, and it changes sign: it overshoots slightly when yields rise.

How far each estimate misses the true price. The duration error grows with the square of the move; the duration-plus-convexity error stays near zero over ±3%\pm 3\%.

Try it

The table above, with the error of each estimate in the last two columns. DD and CC are the values from the first cell.

⌘/Ctrl + Enter runs the cell
Check yourself
Two bonds have the same price and duration. Bond B has higher convexity. Yields move sharply, up or down. Which does better?

Convexity on the desk

Convexity grows quickly with maturity. A zero-coupon bond paying only at TT has C=T(T+1)(1+y)2C = \frac{T(T + 1)}{(1 + y)^2}: for 5 years at 5%, 301.052=27.21\frac{30}{1.05^2} = 27.21. At the same 5% yield:

bondduration DDconvexity CC
5-year, 8% coupon4.149622.57
5-year, 4% coupon4.400324.47
5-year, zero coupon4.761927.21
10-year, 4% coupon7.961578.29
10-year, zero coupon9.523899.77
30-year, 4% coupon16.0942377.43

Convexity grows much faster than duration. From 5 to 10 years, the 4% bond's duration grows 1.81 times and its convexity 3.2 times. For long bonds the correction matters even for moderate moves.

Try it

convexity divides the second central difference by the price. The loop reproduces the table, then the second loop tries four bump sizes on the 5-year 4% bond.

⌘/Ctrl + Enter runs the cell

Risk aversion: a concave utility

Economists describe how much a person values wealth ww with a utility function u(w)u(w). A common choice is u(w)=ln⁡wu(w) = \ln w.

Its slope u′(w)=1wu'(w) = \frac{1}{w} is positive: more is better. Its second derivative u′′(w)=−1w2u''(w) = -\frac{1}{w^2} is negative: each extra dollar adds less than the one before (lessons 2.3.4 and 2.4.2).

Offer someone with $100,000 a fair coin flip: win or lose $20,000. Their expected wealth, the average of the two equally likely outcomes, is still $100,000. But their expected utility is 12ln⁡120,000+12ln⁡80,000=11.4925\frac{1}{2}\ln 120{,}000 + \frac{1}{2}\ln 80{,}000 = 11.4925, below ln⁡100,000=11.5129\ln 100{,}000 = 11.5129.

The reason is the shape. The chord between the two outcomes lies below a concave curve, so the average of the two utilities sits below the utility of the average. The loss hurts more than the gain helps.

Rule: Certainty equivalent and risk premium

u(CE)=expected utilityrisk premium=expected wealth−CE\begin{gathered} u(\text{CE}) = \text{expected utility} \\[4pt] \text{risk premium} \\ = \text{expected wealth} - \text{CE} \end{gathered}

The certainty equivalent CE is the sure wealth that is worth as much to the person as the gamble. For u=ln⁡wu = \ln w, CE=eexpected utility\text{CE} = e^{\text{expected utility}}. The risk premium is what they would give up to avoid the gamble.

Here CE=e11.4925≈\text{CE} = e^{11.4925} \approx $97,979.59, so the risk premium is $2,020.41. The figure shows a larger flip, $50,000 either way, where the shapes are easier to see.

Log utility and a fair flip of $50,000 on $100,000. The expected utility is the midpoint of the chord, below the curve. The curve falls to that height at $86,600, so the person would give up $13,400 to avoid the flip.

How big is the premium?

How strongly a person dislikes risk is the curvature relative to the slope: the Arrow–Pratt coefficient A(w)=−u′′(w)u′(w)A(w) = -\frac{u''(w)}{u'(w)}. For ln⁡w\ln w it is 1w\frac{1}{w}. For a fair flip of ±s\pm s, the premium is about 12A(w) s2\frac{1}{2}A(w)\,s^2: half the curvature times the square of the move, like the convexity term.

stake ss10,00020,00050,000
risk premium501.262,020.4113,397.46
12A(w) s2\frac{1}{2}A(w)\,s^2500.002,000.0012,500.00

Doubling the stake roughly quadruples the premium. The estimate is good for small stakes and too low for large ones. A richer person minds less: with $1,000,000, the same $20,000 flip has a premium of only $200.02.

Try it

The certainty equivalent and risk premium for three stakes, next to 12A(w)s2\frac{1}{2}A(w)s^2 with A(w)=1wA(w) = \frac{1}{w}.

The last two lines print ln⁡100,000\ln 100{,}000 against the expected utility, then the premium at $1,000,000.

⌘/Ctrl + Enter runs the cell

The sign of u′′u'' decides

For the $20,000 flip on $100,000:

utilityu′′u''certainty equivalentrisk premium
ln⁡w\ln wnegative97,979.592,020.41
wwzero100,000.000
w2w^2positive101,980.39−1,980.39-1{,}980.39

A concave utility is risk averse: the premium is positive. A straight line is risk neutral: only the expected wealth matters. A convex utility is risk seeking: the person would pay to take the gamble.

Try it

Each utility comes with its inverse, which turns the expected utility back into wealth.

The last lines try a flip that could lose everything: ln⁡0\ln 0 does not exist, and Python raises ValueError.

⌘/Ctrl + Enter runs the cell

A log-utility investor treats ruin as infinitely bad: as wealth falls towards 0, ln⁡w\ln w falls without limit. So a model must check that every outcome leaves positive wealth before taking logs.

Check yourself
Two people with log utility face the same fair flip of $20,000. One has $100,000, the other $1,000,000. Who would pay more to avoid it?
Exercise

Convexity and certainty equivalents

Write two functions.

  1. convexity(coupon, face, years, y, h=1e-4) returns C=1PP′′(y)C = \frac{1}{P}P''(y) for a bond with yearly coupons, estimating P′′P'' with the second central difference P(y+h)−2P(y)+P(y−h)h2\frac{P(y + h) - 2P(y) + P(y - h)}{h^2}.
  2. certainty_equivalent(w, gain, loss) returns the certainty equivalent, for log utility, of a fair coin flip that adds gain or subtracts loss. If loss would leave no wealth, raise ValueError.
See the tests
def test_convexity():
    """The 5-year 4% bond at 5% has convexity about 24.47"""
    expect_close(convexity(4, 100, 5, 0.05), 24.472405046329648, what="convexity(4, 100, 5, 0.05)", rel=1e-4)


def test_zero_coupon_convexity():
    """A 5-year zero at 5% has convexity 5 × 6 / 1.05²"""
    expect_close(convexity(0, 100, 5, 0.05), 30 / 1.05**2, what="convexity(0, 100, 5, 0.05)", rel=1e-4)


def test_convexity_positive():
    """Bond convexity is positive"""
    c = convexity(7, 100, 20, 0.06)
    assert c > 0, f"expected positive convexity, got {c}"


def test_certainty_equivalent():
    """$100,000 facing a fair ±$20,000 flip: certainty equivalent about $97,980"""
    expect_close(certainty_equivalent(100_000, 20_000, 20_000), 97979.58971132721, what="certainty_equivalent", rel=1e-9)


def test_risk_aversion():
    """The certainty equivalent is below the expected wealth"""
    ce = certainty_equivalent(50_000, 10_000, 10_000)
    assert ce < 50_000, f"expected a certainty equivalent below 50,000, got {ce}"


def test_ruin():
    """A loss that would leave no wealth raises ValueError"""
    try:
        certainty_equivalent(20_000, 20_000, 20_000)
    except ValueError:
        return
    raise AssertionError("expected ValueError when the loss would leave no wealth")

Summary card

  • A bond's price curve is concave up: each payment has second derivative t(t+1)ct(1+y)−t−2>0t(t + 1)c_t(1 + y)^{-t-2} > 0. Convexity is C=1PP′′(y)C = \frac{1}{P}P''(y).
  • ΔPP≈−DΔy+12C(Δy)2\frac{\Delta P}{P} \approx -D\Delta y + \frac{1}{2}C(\Delta y)^2: the correction is positive whichever way yields move, and it grows faster than duration with maturity.
  • Estimate P′′P'' with a 1 bp second central difference; check the scale a system quotes CC in.
  • A concave utility (u′′<0u'' < 0) makes a fair gamble worth less than its expected value. The certainty equivalent has the same utility; the gap to expected wealth is the risk premium, about 12A(w)s2\frac{1}{2}A(w)s^2 with A=−u′′u′A = -\frac{u''}{u'}.

Free further reading

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