Speed

What the Hedge Leaves: Convexity

With DV01 matched, half the difference of convexity times value of the two bonds, times the shift squared, remains; the 10-year bond has more convexity, so the book gains for large moves.

The question

Lesson 4 left a small profit on both sides of a hedge that was exact to first order. Where does it come from? DV01 is the slope of the price against the yield. The price is a curve, and a curve differs from its slope by a second-order term that depends on its curvature, the convexity. When the DV01s cancel, the convexities do not, and that term is what is left (see Convexity Intuition). The bonds, yields and shifts are made-up inputs.

Work it by hand

For a shift s in the yield, the change in a bond's value is about minus DV01 times the shift in basis points, plus one half times convexity times value times s squared. The first part cancels in the hedged book. What is left is one half times the convexity times value of A minus that of the sold B, times s squared.

Take the two zero bonds of the last lessons at 5%: the convexity of A (4 years) is 18.1406 and that of B (1 year) is 1.8141, both rounded to four places. Their values are 822,702.47 and 3,290,809.90, so the products, with the convexities unrounded, are 14,924,307.93 and 5,969,723.17, a difference of 8,954,584.76. For a shift of 0.01 the estimate is 0.5 times 8,954,584.76 times 0.0001, which is 447.73. Lesson 4 priced the same book at +436.56 for a rise and +459.31 for a fall, mean 447.94.

Run it

The program takes the fixed example of the book: A of 1,000,000 face, 5% coupon, 10 years, at 5%, and B with a 4% coupon, 2 years, at 4%. Coupons are paid once a year and yields are yields per year. Lines 4 and 5 give the hedge face, lines 6 and 7 the values of the two positions, and lines 8 and 9 the left-over term with the engine's convexity.

A plot of 17 points for shifts from -200 to +200 basis points: the exact profit of the hedged book, 11,627.74 at -200, falling to 0 at 0 and rising to 9,647.79 at +200, and the convexity estimate, a symmetric curve through 0 that reaches 10,573.81 at both -200 and +200. The answer is 252402, the exact profit at the shift 0.01 in cents.
Watch the steps (recorded video)
market.set_date("2025-01-02");
let a = instrument.bond(face_a, coupon_a, float(years_a), 1);
let b = instrument.bond(1000000.0, coupon_b, float(years_b), 1);
let hedge = risk.bond_dv01_yield(a, yield_a) / risk.bond_dv01_yield(b, yield_b);
hedge = hedge * 1000000.0;
let va = pricing.bond_price_from_yield(a, yield_a) * face_a / 100.0;
let vb = pricing.bond_price_from_yield(b, yield_b) * hedge / 100.0;
let left = 0.5 * (pricing.bond_convexity(a, yield_a) * va);
left = left - 0.5 * (pricing.bond_convexity(b, yield_b) * vb);
let bp = float_list(); let exact = float_list(); let guess = float_list();
for (k in range(0, 17)) {
  let s = 0.0025 * float(k - 8);
  let da = pricing.bond_price_from_yield(a, yield_a + s) * face_a / 100.0 - va;
  let db = pricing.bond_price_from_yield(b, yield_b + s) * hedge / 100.0 - vb;
  bp.add(lmf.round(s * 10000.0, 0)); exact.add(lmf.round(da - db, 2));
  guess.add(lmf.round(left * s * s, 2));
}
let pa = pricing.bond_price_from_yield(a, yield_a + shift);
let pb = pricing.bond_price_from_yield(b, yield_b + shift);
let one = (pa * face_a - pb * hedge) / 100.0 - (va - vb);
lmcode_return_put("bp", bp); lmcode_return_put("exact", exact);
lmcode_return_put("guess", guess);
lmcode_return_put("estimate", lmf.money(left * shift * shift));
let answer = int(math_round(lmf.round(one, 2) * 100.0));
{
  "answer": 252402,
  "bp": [
    -200,
    -175,
    -150,
    -125,
    -100,
    -75,
    -50,
    -25,
    0,
    25,
    50,
    75,
    100,
    125,
    150,
    175,
    200
  ],
  "exact": [
    11627.74,
    8795.71,
    6384.99,
    4381.32,
    2770.87,
    1540.25,
    676.53,
    167.16,
    0,
    163.3,
    645.69,
    1436.15,
    2524.02,
    3898.96,
    5550.97,
    7470.38,
    9647.79
  ],
  "guess": [
    10573.81,
    8095.57,
    5947.77,
    4130.39,
    2643.45,
    1486.94,
    660.86,
    165.22,
    0,
    165.22,
    660.86,
    1486.94,
    2643.45,
    4130.39,
    5947.77,
    8095.57,
    10573.81
  ],
  "estimate": "2,643.45"
}

The convexity is 74.9977 for A and 5.4051 for B. Lines 11 to 17 compare the exact hedged profit with left times the shift squared for 17 shifts. At 100 basis points the estimate is 2,643.45 against exact profits of 2,524.02 for a rise and 2,770.87 for a fall; at 50 basis points 660.86 against 645.69 and 676.53. The answer, on line 24, is the exact profit at shift, in cents: 252402.

You can change all inputs. A yield of -1 or lower for either bond, a face of 0 or below, or a maturity of 0 stops line 4.

A shift that takes bond A's yield to -100% stops line 18 ("got -1.45" for a shift of -1.5; a shift of -0.9 stays above -100% but gives a profit too large to return, and the run stops, without a line, with "lmcode return: invalid JSON value at /answer: unsafe_integer"), and a yield of -0.99 for A stops line 13 ("got -1.01"). The messages are those of the lessons before.

A face of 10^17 or more makes the answer too large to return and stops the run, without a line, with the same "unsafe_integer" text; 10^16 still runs.

Your turn

The program below should return the convexity estimate of the profit of the hedged book for a shift. Several candidate programs are offered. Read them, run them on books of your own, and decide which of them is right for every book. The hedge is the exact DV01 ratio, not rounded. Check runs each candidate on the book shown and on five others.

The face of A, 1500000, the years of A, 8, and of B, 3, the shift 0.02, and the whole number of cents that the shown program returns.
market.set_date("2025-01-02");
let a = instrument.bond(face_a, coupon_a, float(years_a), 1);
let b = instrument.bond(1000000.0, coupon_b, float(years_b), 1);
let hedge = risk.bond_dv01_yield(a, yield_a) / risk.bond_dv01_yield(b, yield_b);
hedge = hedge * 1000000.0;
let va = pricing.bond_price_from_yield(a, yield_a) * face_a / 100.0;
let vb = pricing.bond_price_from_yield(b, yield_b) * hedge / 100.0;
let gap = pricing.bond_convexity(a, yield_a) * va;
gap = gap - pricing.bond_convexity(b, yield_b) * vb;
lmcode_return_put("hedge_face", lmf.money(hedge));
let answer = int(math_round(lmf.round(gap * shift * shift, 2) * 100.0));
{
  "answer": 1777284,
  "hedge_face": "3,784,005.29"
}

Bond A (face face_a, coupon coupon_a once a year, years_a whole years, yield yield_a) is held and bond B (face 1,000,000 as a unit, coupon coupon_b, years_b whole years, yield yield_b) is sold in the amount that makes the DV01 of the book zero (the exact ratio, not rounded). Both yields move by shift. The convexity estimate of the change in a bond's value is one half times its convexity times its value times shift squared. Return, in whole cents, the estimate for the book: that of A minus that of the sold face of B. Check runs your program on this book and on five others.

Read the result carefully

The estimate is symmetric in the shift, and the exact profit is not: the plot shows the gap, which comes from the terms of third order and above that the estimate leaves out. The profit is positive on both sides only because bond A has more convexity times value than the sold bond; if the sold bond had the larger product, the estimate would be negative.

The model moves both yields together and charges nothing for time passing, for borrowing or for trading, so positive convexity looks like a gift only inside the model. The bonds pay for certain and the numbers are inputs, not forecasts. The estimates are rounded to cents with lmf.round.

Recap

  • With the DV01s equal, the first-order term of the hedged book is zero.
  • What is left is one half times the difference of convexity times value of the two bonds, times the shift squared.
  • Bond A has the larger convexity times value, so the book gains for large moves either way: 2,643.45 estimated at 100 basis points.
  • The estimate is symmetric; the exact profit is not.