1. Calculating bond yields
So far, we have been using a known bond yield to calculate its price. Now we are going to work the opposite way around and use a bond's price to calculate its yield.
2. Yield calculation motivation
By calculating the yield to maturity, we can find out what return a bond will offer us if we buy it at the current market price and hold it to maturity.
This can be very useful when comparing different bonds, each with different prices, coupons, and maturities, in order to see which bond offers us the greatest return on our investment.
3. Zero coupon bond yield formula
Lets take our formula for the price of zero coupon bond from the first lesson of this chapter.
We can rearrange this formula to get it in terms of r, in other words, we can use it to find out what the yield to maturity of a zero coupon bond is if we know its price, face value, and maturity.
4. Zero coupon bond yield example
We can then use this formula on our zero coupon bond from the first lesson to solve for the yield to maturity.
The zero coupon bond has a three year maturity, a face value of one hundred dollars, and price of ninety dollars and nineteen cents.
What is its yield?
5. Zero coupon bond yield calculation
Using our formula in Python, we set ytm to be the future value divided by the present value to the nth root, where n is the number of years, minus one.
The easiest way to represent the nth root in Python is to simply raise it to the power of one divided by n.
Printing the result, we get a yield to maturity of three point five percent, the same yield we start off with in lesson one.
Note `yield` already is used in Python for something else, so we will assign yield answers to `ytm` for 'yield to maturity'.
6. Coupon bond yield formula?
Lets now apply the same concept to coupon bearing bonds. We start with our formula for the price of a coupon bond from earlier.
Unfortunately, this cannot be algebraically rearranged to solve for r.
To get around this problem, we can use numerical methods, which are essentially a trial and error process to find the value of r that makes the pv equal to the current bond price.
This is actually the method that the numpy financial rate function uses to solve for the rate.
7. Coupon bond yield example
Taking the example of a coupon paying bond from earlier, we will now flip things around and pretend we know the price of this bond, but not the yield to maturity.
This bond has a maturity of three years, pays a three percent annual coupon, and has a price of ninety seven dollars and twenty two cents.
What is the yield to maturity of this bond?
8. Coupon bond yield calculation
We import numpy financial as usual and use the npf dot rate function to find the yield to maturity of the bond.
We set nper to three as the bond has a three year maturity, pmt to three as the bond pays a three percent coupon, the pv to minus ninety seven point twenty two and fv to one hundred, and get a yield of four percent.
Remember that as numpy financial functions represent money as cash-flows, we need to set the pv to a negative number.
This is because the price of the bond is money we pay (negative cash-flow) in order to receive the coupons and face value of the bond (positive cash-flows) in return.
9. Let's practice!
Now its time for you to get some practice finding the yield to maturity of some bonds!