How do I solve for a bond’s credit spread with brentq?
Build discount factors and spot rates from three government bond prices, write a pricing function with a spread, solve for the spread that matches a corporate bond’s price with scipy.optimize.brentq, and price a second bond and its DV01 at that spread.
After this lesson, you can price a corporate bond from government bond prices and another company’s bond quote.
How do I get spot rates from three government bonds?
A discount factor \(D_t\) is today’s price of one krona paid in year \(t\), and solving the government bonds from the shortest to the longest, called bootstrapping, gives one factor per year. The one-year bond gives \(D_1 = 97.09/100\), and each longer bond’s price minus the value of its earlier coupons, divided by its final payment, gives the next factor. Each factor turns into an annual spot rate, so year 2 is discounted at 4.020%.
Here the two-year bond pays a coupon of 4 and the three-year bond 4.5, both priced at 100, and \(s_t\) is the spot rate of year \(t\) with annual compounding.
The bonds are made up, with prices and coupons per 100 kronor of face value and the next payment one year away. np.arange(1, 4) makes the years 1 to 3.
The following box computes the factors and spot rates.
A corporate bond’s Z-spread is the amount added to every spot rate that makes its discounted payments equal its price. brentq finds the spread where the model price minus the quote is zero, and for AAA’s three-year bond with a coupon of 5 and a price of 96, it is 201.57 basis points.
Here \(c\) is the annual coupon, the payments \(CF_t\) are \(c\), \(c\) and \(100 + c\), and \(z\) is the spread.
price_bond discounts the three payments, and np.full(3, coupon, dtype=float) makes the coupons, to whose last one += 100 adds the principal. brentq(function, 0, 0.10) needs errors of opposite sign at the two bounds, and with bounds of 3% and 10% it raises a ValueError, because both errors are negative. One basis point is 0.0001.
The following box checks the pricing on a government bond and solves for AAA’s spread.
At AAA’s spread, BBB’s bond with a coupon of 6 is worth 98.6682 per 100 of face value, assuming the two companies carry the same spread. Its DV01, the loss for a rise of one basis point in the government rates, is 0.02622, the price with rates one basis point lower minus the price one basis point higher, divided by 2.
A spread wider by 25 basis points lowers BBB’s price by 0.6525, close to \(25 \times 0.02622\), because a basis point of spread raises every discount rate as much as a basis point of the spot curve.
The following box prices BBB, its DV01 and its price at a wider spread.