SpotRate
ForwardRate
SpotRateCurve
Term
Compounding
Daycount
Interpolation
tomonths
and todays
curve[1]
for the first term, curve[2]
for the second and so on.
If the given index exceeds the curve length this operation returns NA
.curve[1] \<- 0.01
curve[["1 day"]]
for 1 day
, curve[["2 days"]]
for 2 days
, ...2 days
index it returns NAMethods to be implemented in the term class:
Bonds can be created using a data.frame
and spotrate
can be set as
one of columns.
# Declaring bonds
dc <- as.daycount('actual/360') # daycount rule
comp <- as.compounding('continuous') # compounding regime
days <- c(97, 242, 321) # days to maturity
sr <- as.spotrate(rep(0.06, length(days)), comp, dc) # discount rate
bonds <- data.frame(DaysToMaturity=days, Rate=sr, Notional=100000)
bonds
# DaysToMaturity Rate Notional
# 1 97 0.06 discrete business/252 ANBIMA 1e+05
# 2 242 0.06 discrete business/252 ANBIMA 1e+05
# 3 321 0.06 discrete business/252 ANBIMA 1e+05
# Pricing bond -- discounting their notional value
within(bonds, {
PV <- Notional*discount(Rate, DaysToMaturity)
})
# DaysToMaturity Rate Notional PV
# 1 97 0.06 continuous actual/360 1e+05 98396.33
# 2 242 0.06 continuous actual/360 1e+05 96046.92
# 3 321 0.06 continuous actual/360 1e+05 94790.59
library(bizdays)
cal <- Calendar(holidays=holidaysANBIMA, name='ANBIMA', weekdays=c('saturday', 'sunday'))
dc <- as.daycount('business/252')
comp <- as.compounding('discrete')
dates <- as.Date(c('2014-09-07', '2015-03-07', '2015-09-07'))
sr <- as.spotrate(rep(0.06, length(dates)), comp, dc, cal)
bonds <- data.frame(RefDate=as.Date('2014-03-21'), Maturity=dates, Rate=sr, Notional=100000)
bonds
# RefDate Maturity Rate Notional
# 1 2014-03-21 2014-09-07 0.06 discrete business/252 ANBIMA 1e+05
# 2 2014-03-21 2015-03-07 0.06 discrete business/252 ANBIMA 1e+05
# 3 2014-03-21 2015-09-07 0.06 discrete business/252 ANBIMA 1e+05
within(bonds, {
PV <- Notional*discount(Rate, from=RefDate, to=Maturity)
})
# RefDate Maturity Rate Notional PV
# 1 2014-03-21 2014-09-07 0.06 discrete business/252 ANBIMA 1e+05 97353.43
# 2 2014-03-21 2015-03-07 0.06 discrete business/252 ANBIMA 1e+05 94558.01
# 3 2014-03-21 2015-09-07 0.06 discrete business/252 ANBIMA 1e+05 91842.86
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.