Tutorials by Brand:
How to Calculate Duration and Convexity of a Bond on the HP 12C

Duration and convexity are important numbers in bond portfolio management, but it is far from obvious how to calculate them on the HP 12C. Of course, there are formulas that you can type in (see below), but they aren’t easy for most people to remember and are tedious to enter. In this article I will show you how you can use a very accurate approximation method that is easy to use on the HP 12C. In fact, the accuracy of these simple approximations are more than good enough. They will generally be the same as the exact solution to two or more decimal places.
The usual formulas for calculating Macaulay duration, modified duration, and convexity are given in the table below. Obviously, the summations make the calculations tedious. There are closed-form solutions for these equations, but they are fairly long and ugly. In other words, they aren’t really suited for a calculator solution.
| Formula for | Formula |
| Macaulay Duration | $$\frac{1}{P}\sum\limits_{t = 1}^N {\frac{{C{F_t}}}{{{{\left( {1 + i} \right)}^t}}}} \times t$$ |
| Modified Duration | $${\frac{1}{{P \times \left( {1 + i} \right)}}\sum\limits_{t = 1}^N {\frac{{C{F_t}}}{{{{\left( {1 + i} \right)}^t}}}} \times t}$$ |
| Convexity | $$\frac{1}{{P \times {{\left( {1 + i} \right)}^2}}}\sum\limits_{t = 1}^N {\frac{{C{F_t}}}{{{{\left( {1 + i} \right)}^t}}}} \times \left( {{t^2} + t} \right)$$ |
In the equations, $P$ is the bond price, $CF_t$ is the cash flow in period $t$, and $i$ is the per period yield to maturity. It is important to note that these equations work only on an interest payment date.
Warning!
There is a little bit of calculus in this article, but you can safely ignore it if you aren’t comfortable with it. The solutions that I will present don’t require any knowledge of calculus.
Modified Duration
Most investments textbooks start their discussion of duration with Macaulay duration, but we will start with modified duration because it is a bit more straightforward. Modified duration is the first derivative of the bond pricing equation with respect to the yield ($i$), divided by the price ($P$) of the bond:
$${\rm{Modified\, Duration}} = \frac{{\partial P}}{{\partial i}} \times \frac{1}{P}$$
We know how to calculate the price of a bond using the HP 12C, so the problem here is how to calculate that partial derivative. Recall that a partial derivative tells you how much a function changes when one of its variables changes by a small amount. More specifically, this partial derivative will tell us how much the bond price will change when the yield changes by a small amount (say from 5% to 5.1%). When we take this change and divide it by the current price, we are simply converting the dollar change into a percentage change. So you can see that this derivative will tell us how sensitive a bond’s price will be to changes in interest rates.
We can approximate a first partial derivative by using a technique called “centered differencing.” Simply perturb the yield by a tiny amount and recalculate the price. Do this twice (above and below the yield) and then divide by two times the change in yield:
$$\frac{{\partial P}}{{\partial i}} \cong \frac{{{P_{i – h}} \,- {P_{i + h}}}}{{2h}}$$
In the equation, $h$ is the small change in the yield, $P_{i+h}$ is the bond price at a slightly higher yield, and $P_{i−h}$ is the price at a slightly lower yield. We will set $h=0.00001$, though you could use a smaller change. Now, we can approximate the modified duration with the formula:
$${\rm{Modified\, Duration}} \cong \frac{{{P_{i – h}} \,- {P_{i + h}}}}{{2h}} \times \frac{1}{P}$$
Let’s look at an example:
Imagine that you are considering the purchase of a bond with a face value of $1,000 and a coupon rate of 8% paid semiannually. The bond matures in 20 years and the yield to maturity is 6%. What is the modified duration of this bond?
We need to find the bond price three times to use our approximations for the duration measures. Further, we will set $i = i \pm h$ (note that since the calculator requires i to be in percent, you will need to multiply this by 100) . To find the initial bond price (P), enter N = 40, i = 3, PMT = 40, FV = 1000, and then solve for PV. You should get -1,231.148. Change the sign and save this in memory by pressing STO and then 1. Next, we will use the same inputs, except that we set i = 2.9 and when we solve for PV we get -1,258.423, which is $P_{i-h}$. Again, press CHS and save this in memory by pressing STO and then 2. Finally, we set i = 3.1 and solve for PV again. This third time you will get -1,204.711, which is $P_{i+h}$. Save this in memory by pressing CHS STO and then 3.
Now, we can recall each of the saved prices by pressing RCL (recall) and then 1 to get the original price, or RCL 2 to get the second price, etc. We are now ready to find the approximate modified duration by using our formula from above:
$${\rm{Modified\, Duration}} \cong \frac{{1258.423 \,- 1204.711}}{{2 \times 0.001}} \times \frac{1}{{1231.148}} = 21.814$$
Realize that this result is the modified duration in semiannual periods, so divide by 2 to get 10.907 years.
Note
This general technique can be used for all of the partial derivative approximations in this article. That is, we solve for the price of the bond three times, saving each of the prices in a memory location by pressing STO and a number key. We can then RCL recall these prices as needed. Be sure to remember which price you put into which memory location. I typically would place the prices as follows: $P$ goes into 1, $P_{i\,-h}$ goes into 2, and $P_{i+h}$ goes into 3 as I did above.
Note also that you need to be careful to not set the yield change ($h$) to be too small. If you do, then you will have an underflow and the answer that you get will be incorrect. That is why I chose $h = 0.001 = 0.1\%$ for this article, though a smaller $h$ would improve the approximation, as long as you don’t go too small.
Macaulay Duration
Once you have found the modified duration, Macaulay duration is easy because we simply multiply by 1 plus the per period yield:
$${\rm{Macaulay\, Duration}} = {\rm{Modified\, Duration}} \times \left( {1 + i} \right) \cong \frac{{{P_{i – h}} \,- {P_{i + h}}}}{{2h}} \times \frac{{\left( {1 + i} \right)}}{P}$$
Using the example problem from above, recall that we got 10.905 years for the modified duration. Therefore, the Macaulay duration is $10.907\times 1.03=11.234$ years.
Convexity
To calculate convexity on a financial calculator is only slightly more complicated, but the idea is the same. That is, approximate the derivative and then divide by the current price. The convexity of a bond measures the amount of curvature in the price/yield relationship and its formula is:
$${\rm{Convexity}} = \frac{{{\partial ^2}P}}{{\partial {i^2}}} \times \frac{1}{P}$$
In other words, convexity is the second derivative of the price formula with respect to the yield divided by the price of the bond.
As before, our first task is to approximate the derivative. In this case, we will use the central difference approximation:
$${\rm{Convexity}} \cong \frac{{{P_{i – h}} + {P_{i + h}} \,- 2P}}{{{h^2}}} \times \frac{1}{P}$$
Notice that, as before, we need three prices (current price and two with the yield changed slightly). If you still have those prices in memory, then you simply enter them into the above equation. If not, then recall that we calculated the current price at a yield of 3% per period ($P=1,231.148$), the price at a yield of 2.999% per period ($P_{i−h}=1,231.416$), and the price at a yield of 3.001% per period ($P_{i+h}=1,230.879$). Now, we simply plug those numbers into our approximate convexity formula:
$${\rm{Convexity}} \cong \frac{{1,258.423 + 1,204.711 \,- 2 \times 1,231.148}}{{{{0.001}^2}}} \times \frac{1}{{1,231.148}} = 681.109$$
If we wish to annualize the convexity, we divide by the payment frequency squared ($2^2$ here) to get 170.277.
Conclusion and One Caveat
We have seen here that we can easily calculate modified duration, Macaulay duration, and convexity using a financial calculator. This is easy because we calculate the price three times: at the existing yield, at a slightly lower yield, and at a slightly higher yield. Using the memory function of your calculator, you can save these prices and then plug them into the approximation formulas given above. The approximations are very accurate as the table below shows:
| Annualized Measure | Exact Solution | Approximate Solution | Same to |
| Modified Duration | 10.90499629 | 10.9070280 | 2 decimal places |
| Macaulay Duration | 11.23214617 | 11.2342388 | 2 decimal places |
| Convexity | 170.25762159 | 170.2771947 | 1 decimal places |
This degree of accuracy is good enough for all practical purposes. So, there is really no need to memorize the complicated exact formulas for these bond risk measures. Note that the convexity approximation is accurate to 5 decimal places when using Excel. I assume that the difference is due to Excel’s 15 digits of precision, versus the calculator’s 10 digits.
One caveat to this article is that I have only shown how to do these calculations on a coupon payment date. Extending the approximations to work on any date is quite straightforward: Simply use the dirty prices of the bond in place of payment date prices that I have used in the examples above. I show how to calculate the price of a bond on any date elsewhere on TVMCalcs.com.
