The brief
A fixed-income desk's overnight risk report estimates each bond's price change from its derivatives instead of repricing the bond. The head of risk accepts an estimate only while it is within 5 cents, per 100 of face value, of the repriced change.
She wants to know, for each bond in the book, how large a yield move each estimate can take before it breaks that limit. She also wants a quick rule that predicts the answer without repricing.
Your task
- Write
price_derivatives(flows, y, n): the list[P, P', ..., P^(n)], the price and its firstnderivatives in the yield, aty.flowsis a list of(t, amount)pairs, each payment discounted by . RaiseValueErrorif ornis negative. - Write
taylor_change(flows, y, dy, order): the price change for a yield movedy, estimated by the Taylor polynomial of degreeorder. Order 1 uses the slope alone; order 2 adds the bend. RaiseValueErroriforderis below 1. - Write
breakdown_move(flows, y, order, tol): the smallest move, in whole basis points, at which the estimate misses the repriced change by more thantol. Try 1, 2, 3 and so on up to 1,000 bp, both up and down at each size. ReturnNoneif no move up to 1,000 bp breaks the limit. - Write
predicted_move(flows, y, order, tol): the move, in basis points, at which the first term the estimate leaves out reachestolin size.
Both of the last two raise ValueError if tol is not positive.
The data
BONDS holds the book: each bond has a name, a yearly coupon, its years to maturity and its yield, compounded once a year. cash_flows(coupon, years) turns a bond into its payments. TOLERANCE is the 5-cent limit.
Hint: Where to start
Differentiate again and again with the power and chain rules (lessons 2.3.1 and 2.3.3). Going from the -th derivative to the next multiplies by and lowers the power by one. Case studies 2.3.7, 2.4.5 and 2.7.4 find the first three.
Hint: The estimate and its error
In step form, the Taylor polynomial of degree gives the change (lesson 2.7.1). Near , its error behaves like the first power it leaves out, .
Hint: Predicting the limit
Lesson 2.7.2 uses the first left-out term, , as an estimate of the error. Set its size equal to tol and solve for .