Bond pricing

Bonds are very important financial instruments as they provide cash flow at a certain time at the predetermined rate or current market rate. Bonds help investors to create well-diversified portfolios. One must calculate bond price, yield, and maturity precisely to get a better idea of the instrument. We are going to use package termstrc for this. We have to install and load it into the R workspace using the following code:

> install.packages('termstrc') 
> library('termstrc') 

We will use the data govtbonds in the package, which can be loaded and viewed using the following code:

> data(govbonds) 
> govbonds 
This is a data set of coupon bonds for: 
GERMANY AUSTRIA FRANCE ,  
observed at 2008-01-30. 

The variable govbonds has bond data for three countries - Germany, Austria, and France. We will be using the Germany data to calculate bond prices, which can be accessed using govbonds[[1]]. The following two lines of code generate cashflow and maturity matrix:

> cashflow <- create_cashflows_matrix(govbonds[[1]]) 
> maturity <- create_maturities_matrix(govbonds[[1]]) 

Next, we will look at the usage of bond_prices(), which calculates the bond prices. beta is another parameter to be supplied to the function bond_prices(). Next we can create the beta variable and defined bond_prices(). The first parameter in this function is method, which supports three methods:

  • ns for Nelson/Siegel
  • dl for Diebold/Li
  • sv for the Svensson approach

We will choose the ns method for the following code:

> beta <- c(0.0323,-0.023,-0.0403,3.234) 
> bp <-  bond_prices(method="ns",beta,maturity,cashflow) 

The variable bp has spot rates, discount factors, and bond prices. Any information can be accessed using $. For example, you can bond prices using the following code:

> bp$bond_prices 

Bond yield is investor return which is realized on bond investment, and it can be calculated using bond_yields(). The following two lines of code generate cashflow and maturity matrices, which include dirty prices as well:

> cashflow <- create_cashflows_matrix(govbonds[[1]],include_price=T) 
> maturity <- create_maturities_matrix(govbonds[[1]],include_price=T) 

The following code calculates the bond yield and maturities in matrix form:

>by <- bond_yields(cashflow,maturity) 

The output of the preceding code can be seen by typing the following command head() and the output has two columns, where the first column of the output matrix is maturity in years and the second column is the corresponding bond yield for the corresponding bonds. Bond names are given as an index of output:

> head(by) 
                             Maturity                          Yield         
DE0001141414                0.04383562                      0.03525805 
DE0001137131                0.12054795                      0.03424302 
DE0001141422                0.19726027                      0.03798065 
DE0001137149                0.36986301                      0.03773425 

The following figure shows yield curve or term structure against various maturities. Yields fluctuate initially for a very small maturity period and continuously increase as the maturity increases:

Bond pricing

Figure 9.4: Yield curve, that is, term structure with different maturities

Duration measures the length of time it takes for the price of the bond to be repaid by its internal cashflow. It is a very important factor for investors to consider, as bonds with higher duration carry more risk and higher price volatility than bonds with lower duration. Duration can be measured using the following code:

>   dur <- duration(cashflow,maturity, by[,"Yield"]) 

It returns duration in years, modified duration, and weights for all bonds in the portfolio. If you want to look at the portfolio composition, you can see the third column of the output matrix. The third column is weights for your investment and you would see that the sum of the weights is equal to 1:

> sum(dur[,3]) 
[1] 1 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset