The brief
A bank's risk desk holds a book of four corporate bonds worth about $7.9 million. A 1 bp rise in yields costs it about $5,100, and the desk's limit allows almost none of that. It hedges by selling government bonds.
A hedge that matches only duration still leaves the book exposed to large moves. The desk wants a hedge in two government bonds that matches both duration and convexity, tested on a 200 bp shock.
Your task
- Write
bond_risk(coupon, years, y): the tuple(price, D, C)per 100 of face value, withDthe modified duration andCthe convexity. The bond payscouponeach year and 100 at the end ofyearsyears; its yieldyis compounded once a year. RaiseValueErrorif . - Write
book_risk(positions): the tuple(V, V1, V2), whereVis the value of the positions.V1andV2are its first and second derivatives in , when every yield moves by the same amount , at . - Write
hedge(positions, hedges): the list of quantities of the hedge bonds to add. With two bonds, the hedged book hasV1andV2both zero; with one bond, onlyV1. RaiseValueErrorfor any other number of bonds, or if two bonds give no single answer. - Write
shocked_value(positions, shift): the value of the positions after every yield moves byshift, from full repricing. RaiseValueErrorif a yield would reach .
The data
Each position in BOOK is a dict with coupon, years, yield and quantity. The quantity is a number of bonds of 100 face value, negative when short. HEDGES holds the 5-year and 30-year government bonds the desk can trade, without quantities.
Hint: Where to start
Case study 2.3.7 gives the exact duration and case study 2.4.5 the exact convexity , both as sums over the payments. A shift in every yield moves each price as its own yield would (the chain rule, lesson 2.3.3). So the sum rule (lesson 2.3.1) gives and .
Hint: Two equations, two quantities
Hedge bonds and add to V1 and to V2. Set both totals to zero. Make the subject of one equation (lesson 0.3.2) and substitute it into the other; a zero denominator means no single answer.
Hint: Checking the hedge
Once V1 and V2 are zero, what is left of the profit or loss grows about like the cube of the move. Case study 2.4.5 saw the same: doubling the move made the duration–convexity error about eight times larger.