[This article was first published on K & L Fintech Modeling, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post explains how to calculate the price of some complicated coupon bearing bond using R code.

Pricing of Coupon Bond using R code

There are pricing formula for coupon bond as well as discount bond which are used among practioners under the market convention.

Bond Pricing Formula

1. Discount Bond

2. \begin{align} P = \frac{F}{(1+r)^T \left( 1+r \times \frac{D}{Y} \right)} \end{align} $$P$$ : price
$$F$$ : notional amount (10,000원)
$$r$$ : yield
$$T$$ : number of years from settlement date, which is a multiple of 1 year.
$$D$$ : remaining maturity – T
$$Y$$ : 실제일수 actual days

3. Coupon Bond

4. \begin{align} P &= \left[ I_1 + \frac{I_2}{\left( 1+\frac{r}{K} \right)^1} + \frac{I_3}{\left( 1+\frac{r}{K} \right)^2} \\ + … + \frac{I_n}{\left( 1+\frac{r}{K} \right)^{n-1}} + \frac{F} {\left( 1+\frac{r}{K} \right)^{n-1}} \right] \\ &\quad ÷ \left( 1 + \frac{r}{K} \times \frac{D^{‘}}{B} \right) \end{align} $$P$$ : price
$$I_n$$ : n-th interest amount per 10,000 currency
$$r$$ : yield to maturity
$$K$$ : interet payment frequency within 1 year
$$F$$ : notional amount (10,000)
$$D^{‘}$$ : actual number of days between settlement date ($$t_{val}$$) and the next interest payment date ($$t_{ni}$$)
$$B$$ :actual number of days between the previous interest payment date ($$t_{pi}$$) and the next interest payment date ($$t_{ni}$$)
$$n$$ : total number of interest payments until maturity
From the above formula, denominator $$\left( 1 + \frac{r}{K} \times \frac{D^{‘}}{B} \right)$$ indicates that if valuation date $$t_{val}$$ fall on between interest payment dates $$( t_{pi} \lt t_{val} \lt t_{ni} )$$, the simple interest rate calculation is applied to the period $$t_{val} – t_{ni}$$, not continously compounding.

Bond Pricing Example

The following table shows the cash flow schedule of coupon bond with in-advance interest payments. From the fact that the number of cash flow starts from 8 to 14, we can find that the recent settled cash flow payment is 6th not 7th. This contract is of in-advance interest payment features. See the accrual begin date and payment date.
Consider two cases :
1. valuation date = 7th interest payment date
2. 7th interet payment date < valuation date < 8th interest payment date

The maturity date is 2019-07-29 which is 4 more days later than 2019-07-25 (last day in a quarterly basis). Taking this into account, we can draw cash flows time lines for two cases.

In other words, since maturity date is 2019-07-29, interet for 4 remaining days is paid at 2019-07-25 in advance. Of couse, principal redemption is made at 2019-07-29.

But for calculation is done for the second case since the second case is more general than the first and the first case is simple to calculate. With these in-advance payment features, the pricing equation for this coupon bond (clean price) at 2018-03-22 is as follows.

The explanation of pricing process with cash flow timeline and equation above is

1) Amount in [ ] is the discounted value of all cashflows since 2018/04/16 evaluating at 2018/04/26 (first payment date) not 2018/03/22 (valuation date).

2) Discount amount in [] with 35/90 quarter simply compouding to 2018/03/22 value (dirty price).

3) The portion of 35/90 in interest previously paid at 2018/01/26 should be returned to buyer. This is called as accrued interest and reflected to the last term.

4) Therefore, dirty price + accrued interest is the clean price which is equal to $$P$$.

It is a market convention that dirty and clean price of in-advance interest payments is the other way around of regular coupon bond with in-arrears interest payment.

R code for Bond Pricing

The following R code is implemented using the above formula and specific considerations such as in-advance features, in-between settlement, … etc.
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 #=========================================================================## Financial Econometrics & Derivatives, ML/DL using R, Python, Tensorflow # by Sang-Heon Lee ## https://kiandlee.blogspot.com #————————————————————————-## Coupon Bond Valuation with in advance interest payment#=========================================================================# graphics.off()  # clear all graphsrm(list=ls())   # clear all datasets #—————————————————————–## Specification#—————————————————————–## valuation date   : 2018-03-22# maturity date    : 2019-07-29# coupon rate      : annual 6.2%, quarterly coupon with in advance# principal amount : Bullet repayment at maturity #—————————————————————–#     cpn.rate <– 0.062    # coupon rate    int.rate <– 0.062    # interest rate    mat.qrt  <– 6        # # of interest payments     # initialization    cpn.amt <– 0  # coupon payments    prn.amt <– 0  # principal amount    price   <– 0  # bond price        # 2018.04.26’s discounted value of coupon payments    for (t in 0:(mat.qrt–2)) {         cpn.amt <– cpn.amt + (cpn.rate/4)*10000/                             (1+int.rate/4)^t    }        # 2018.04.26’s discounted value of     # 4-day coupon payment at 2019.07.25    cpn.amt <– cpn.amt + (cpn.rate/4)*(4/93)*10000/                         (1+int.rate/4)^(mat.qrt–1)     # 2018.04.26’s discounted value of     #principal amount at 2019.07.29    prn.amt <– 10000/              ((1+(int.rate/4)*(4/93))*(1+int.rate/4)^(mat.qrt–1))        # 2018.04.26’s bond price    price <– cpn.amt + prn.amt        print(paste(” bond price before discounting at pricing date:”, price))     #—————————————————————–#    # 2018.03.22’s discounted value of all cash flow    # = present value of all cash flow    # = bond price at valuation date    #—————————————————————–#    # present value discounted at pricing date using simple interest     #—————————————————————–#    price = price/(1+(int.rate/4)*(35/90))        print(paste(“bond price discounting at pricing date using simple interest :”, price))        dirty.price      <– round(price,2)    accrued.interest <– round((10000*int.rate/4)*(35/90),2)    clean.price      <– round(dirty.price + accrued.interest,2)     print(“clean price = dirty price + accrued interest”)     print(paste(clean.price, “=”, price, “+”, accrued.interest)) Colored by Color Scripter cs

The result is as follows.
 1234 [1] “price before discounting at pricing date: 10011.47”[1] “price discounting at pricing date using simple interest: 9951.49”[1] “clean price = dirty price + accrued interest”[1] “10011.77 = 9951.4922404715 + 60.28” cs

This post has showed the pricing of some complicated coupon bond, not simple regular coupon bond. But the bottom line is to apply simple interest to incomplete accrual period and compound interest to complete accrual period.

Next time, let’s dive into YTM(Yield to Maturity) and reinvestment risk with EXCEL illustrations and R code. $$\blacksquare$$

To leave a comment for the author, please follow the link and comment on their blog: K & L Fintech Modeling.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)