RStudio Program
R-programming assignment:
1) Open a new R-script and create R commands for the following questions.
(a) Create a function that can value a semi-annual bond using the traditional approach.
The formula is
SemiAnnCoupBond <- function(C,r,N,M){
C*(1/r-1/(r*(1+r)^N))+M/(1+r)^N
}
(b) Using the function from (a), compute a 6% semiannual coupon security maturing in 5 years. Assume that the discount rate is 8%. $1000 fixed income market.
(c) Using the function from (a) and the example in (b), draw a plot that shows the price/discount relationship (Hint: your result should be similar to a plot in Exhibit 4.1 (pp.85)).
(d) Create another function that is able to value a bond following the arbitrage-free valuation approach.
AnnCoupBond1 <- function(C,r,N,M){
PVC = C*sum(1/(1+r)^(1:N))
PVM = M*1/(1+r)^N
PVC + PVM
}
(e) Using the function from (d), compute a 6% 15-year semi-annual bond price based on spot rates in Exhibit 4.8 on page 99.
(f) Provide your R command that is able to plot a chart in Exhibit 4.3. Note that use information in Exhibit 4.2.