The Hedge Ratio
To offset the DV01 of a bond, sell the face of another bond whose DV01 is equal: the DV01 of the position divided by the DV01 of one unit of face of the hedge.
The question
A holder of 1,000,000 of a 10-year bond, bond A, wants the value of the book to stay put when yields move a little. Another bond, bond B, with 2 years to run, can be sold against it. How much of bond B has to be sold? The answer comes from the DV01 of the last lessons: sell enough that the DV01 of what is sold equals the DV01 of what is held. The bonds, their yields and the face are made-up inputs of a model.
Work it by hand
The hedge face is the DV01 of the position divided by the DV01 of one unit of face of the hedge bond. Take two zero bonds that pay only at the end, both at a yield of 5%. Bond A, 4 years, face 1,000,000, has a DV01 of 313.41. One million of bond B, 1 year, has a DV01 of 90.70.
One million of B offsets 90.70, so the face needed is 1,000,000 times 313.41 divided by 90.70, with both DV01s unrounded (they are shown rounded to cents).
For these two zero bonds the ratio is 4 / 1.05^3 = 3.45535, so sell 3,455,350.39 of B; the rounded figures would give 3,455,457.55. Check it: that face of B has a DV01 of 313.41, and with B sold the book's DV01 is 313.41 minus 313.41, which is zero. DV01 is in currency for the whole face, so the ratio must use DV01s of the same face.
Run it
The program takes bond A of 1,000,000 face, a 5% coupon paid once a year, 10 years and a yield of 5% a year, and bond B on the same terms with a 4% coupon, 2 years and a yield of 4%. Line 4 takes the DV01 of A, and line 5 the DV01 of 1,000,000 of B; line 6 divides them to get the hedge face.

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 dv_a = risk.bond_dv01_yield(a, yield_a);
let dv_b = risk.bond_dv01_yield(b, yield_b);
let hedge = dv_a / dv_b * 1000000.0;
let held = hedge / 1000000.0 * dv_b;
let labels = str_list();
labels.add("bond A"); labels.add("sold bond B"); labels.add("net");
let shown = float_list();
shown.add(lmf.round(dv_a, 2)); shown.add(lmf.round(0.0 - held, 2));
shown.add(lmf.round(dv_a - held, 2));
lmcode_return_put("labels", labels); lmcode_return_put("shown", shown);
lmcode_return_put("per_million", lmf.money(dv_b));
lmcode_return_put("hedge_face", lmf.money(hedge));
let answer = int(math_round(hedge / face_a * 1000.0));
{
"answer": 4094,
"labels": [
"bond A",
"sold bond B",
"net"
],
"shown": [
772.17,
-772.17,
0
],
"per_million": "188.61",
"hedge_face": "4,094,033.58"
}The DV01 of A is 772.17 and that of 1,000,000 of B is 188.61, so the hedge face is 4,094,033.58, 4.094 times the face of A. Line 7 takes the DV01 of the sold bond. The picture shows 772.17, minus 772.17 and a net of 0.00, which draws no bar.
The net is zero by construction, because the sold face was chosen to make it so; the next lesson reprices the book. The answer on line 16 is the hedge face in thousandths of the face of A, 4094.
You can change all seven inputs. A yield of -1 or lower stops line 4 (bond A) or line 5 (bond B) with "risk.bond_dv01_yield: yield must be above -100% per coupon period (above -100% a year for 1 period a year), got -1".
A face of 0 or below stops line 4 with "face value must be positive", and a number of years of 0 or more than 100 stops the line of that bond with "bond maturity must be between 0 and 100 years". A coupon of 0 does not stop; a coupon of -1 on a 1-year bond B gives it a DV01 of 0 and stops line 11 with "LmfApi.round argument 1 must be finite".
Your turn
The program below should return the face of bond B to sell. Several candidate programs are offered. Read them, run them on pairs of bonds of your own, and decide which of them is right for every pair. Check runs each candidate on the bonds shown and on five others.

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 dv_a = risk.bond_dv01_yield(a, yield_a);
let long_dur = pricing.bond_duration(a, yield_a);
let hedge = face_a * long_dur / pricing.bond_duration(b, yield_b);
lmcode_return_put("dv01_of_a", lmf.money(dv_a));
let answer = int(math_round(lmf.round(hedge, 0)));
{
"answer": 2701279,
"dv01_of_a": "891.84"
}Bond A has the face face_a, the coupon coupon_a paid once a year, years_a whole years and the yield yield_a. Bond B has the coupon coupon_b, years_b whole years and the yield yield_b. Return, in whole units of face, the face of bond B that must be sold so that the DV01 of the book (A held, B sold) is zero. DV01 is the change in a bond's value for one basis point of its own yield, in currency for the whole face. Check runs your program on these two bonds and on five others.
Read the result carefully
The hedge is built for one thing: both yields moving by the same amount, a little. The model ignores what the short sale costs, that bond B matures in two years and has to be replaced, coupons paid in between, and every risk that is not the yield. The yields are inputs, not forecasts, and a bond is assumed to pay for certain.
The hedge face is returned in whole units so that Check can compare it exactly; unrounded it is 4,094,033.58 in the demo. Two bonds can only be compared this way in currency of the same face, so the ratio uses the DV01 of 1,000,000 of bond B, not of a face of 100. The next lesson moves both yields by a larger amount and shows what the hedge leaves.
Recap
- Hedge face = DV01 of the position divided by the DV01 of one unit of face of the hedge bond.
- With that much of bond B sold, the DV01 of the book is zero.
- DV01 is in currency for the whole face, so the two DV01s must be taken for known faces.
- The hedge is exact only for a small, equal move of both yields.