raw: logical: default FALSE. Compute duration/convexity as derivative of cashflows' present value? Use this if you want to approximate the change in the bond price by a Taylor series (see Examples).
Details
vanillaBond computes the present value of a vector of cashflows; it may thus be used to evaluate not just bonds but any instrument that can be reduced to a deterministic set of cashflows.
ytm uses Newton's method to compute the yield-to-maturity of a bond (a.k.a. internal interest rate). When used with a bond, the initial outlay (i.e. the bonds dirty price) needs be included in the vector of cashflows. For a coupon bond, a good starting value y0 is the coupon divided by the dirty price of the bond.
An offset can be specified either as a single number or as a vector of zero rates. See Examples.
Returns
numeric
References
Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. tools:::Rd_expr_doi("10.1016/C2017-0-01621-X")
Author(s)
Enrico Schumann
See Also
NS, NSS
Examples
## ytmcf <- c(5,5,5,5,5,105)## cashflowstimes <-1:6## maturitiesy <-0.0127## the "true" yieldb0 <- vanillaBond(cf, times, yields = y)cf <- c(-b0, cf); times <- c(0, times)ytm(cf, times)## ... with offsetcf <- c(5,5,5,5,5,105)## cashflowstimes <-1:6## maturitiesy <-0.02+0.01## risk-free 2% + risk-premium 1%b0 <- vanillaBond(cf, times, yields = y)cf <- c(-b0, cf); times <- c(0, times)ytm(cf, times, offset =0.02)## ... only the risk-premiumcf <- c(5,5,5,5,5,105)## cashflowstimes <-1:6## maturitiesy <- NS(c(6,9,10,5)/100, times)## risk-premium 1%b0 <- vanillaBond(cf, times, yields = y +0.01)cf <- c(-b0, cf); times <- c(0, times)ytm(cf, times, offset = c(0,y))## ... only the risk-premium## bondscf <- c(5,5,5,5,5,105)## cashflowstimes <-1:6## maturitiesdf <-1/(1+y)^times ## discount factorsall.equal(vanillaBond(cf, times, df), vanillaBond(cf, times, yields = y))## ... using Nelson--SiegelvanillaBond(cf, times, yields = NS(c(0.03,0,0,1), times))## several bonds## cashflows are numeric vectors in a list 'cf',## times-to-payment are are numeric vectors in a## list 'times'times <- list(1:3,1:4,0.5+0:5)cf <- list(c(6,6,106), c(4,4,4,104), c(2,2,2,2,2,102))alltimes <- sort(unique(unlist(times)))M <- array(0, dim = c(length(cf), length(alltimes)))for(i in seq_along(times)) M[i, match(times[[i]], alltimes)]<- cf[[i]]rownames(M)<- paste("bond.",1:3, sep ="")colnames(M)<- format(alltimes, nsmall =1)vanillaBond(cf = M, times = alltimes, yields =0.02)## duration/convexitycf <- c(5,5,5,5,5,105)## cashflowstimes <-1:6## maturitiesy <-0.0527## yield to maturityd <-0.001## change in yield (+10 bp)vanillaBond(cf, times, yields = y + d)- vanillaBond(cf, times, yields = y)duration(cf, times, yield = y, raw =TRUE)* d
duration(cf, times, yield = y, raw =TRUE)* d + convexity(cf, times, yield = y, raw =TRUE)/2* d^2