diff options
Diffstat (limited to 'R/cds_functions_generic.R')
| -rw-r--r-- | R/cds_functions_generic.R | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 72e52528..1e0b54b8 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -37,16 +37,16 @@ setGeneric("couponleg", function(cs, sc, ...) { ## write couponleg methods for the four types of curves
setMethod("couponleg", signature("data.frame", "flatcurve"),
- function(cs, sc, startdate=Sys.Date() + 1, accruedondefault=TRUE){
+ function(cs, sc, startdate=Sys.Date() + 1, accruedondefault=FALSE){
stopifnot(class(startdate)=="Date")
stopifnot(is.logical(accruedondefault))
cs <- cs[cs$dates>=startdate,]
T <- yearFrac(startdate, cs$dates)
PD <- exp(- sc@h * T )
- if(accruedondefault){
- PDadj <- 0.5 * (c(1, PD[-length(PD)]) + PD)
+ PDadj <- if(accruedondefault){
+ 0.5 * (c(1, PD[-length(PD)]) + PD)
}else{
- PDadj <- PD
+ PD
}
return( as.numeric(crossprod(PDadj, cs$coupons * cs$df)) )
})
@@ -452,7 +452,7 @@ dcds.parspread <- function(cs, sc, recovery, tradedate){ snacpv <- function(cs, parspread, coupon, recovery, tradedate){
## compute the equivalent pv of a snac quote
startdate <- tradedate + 1
- sc <- new("flatcurve", h=parspread/(1-recovery))
+ sc <- new("flatcurve", h=365/360*parspread/(1-recovery))
epsilon <- 1e-8
while(abs(cds.parspread(cs, sc, recovery, tradedate)-parspread)>epsilon){
sc@h <- sc@h - (cds.parspread(cs, sc, recovery, tradedate)-parspread)/
@@ -852,8 +852,9 @@ forward.prot <- function(index, exerciseDate){ defaultAdjustedForwardIndexPrice <- function(index, exerciseDate, fixedRate=0.05){
tes <- addBusDay(exerciseDate)
df <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(index$tradedate, tes))$discounts
- price <- 1 - FEP(index, exerciseDate) + 1/df*(forward.cl(index, exerciseDate)*fixedRate -
- forward.prot(index, exerciseDate)-cdsAccrued(exerciseDate, fixedRate))
+ price <- 1 - FEP(index, exerciseDate) +
+ 1/df*(forward.cl(index, exerciseDate)*fixedRate -
+ forward.prot(index, exerciseDate)-cdsAccrued(exerciseDate, fixedRate))
return( price )
}
@@ -864,6 +865,7 @@ forwardflatcds <- function(h, cs, tradeDate, exerciseDate, fixedRate=0.05, R=0.4 sc <- new("flatcurve", h=h)
cl <- couponleg(cs, sc, startdate=exerciseDate)
pl <- defaultleg(cs, sc, recovery=R, startdate=exerciseDate)
- price <- 1-fep+1/df*(cl*fixedRate-pl-cdsAccrued(exerciseDate, fixedRate))
+ price <- 1 - fep +
+ 1/df*(cl*fixedRate-pl-cdsAccrued(exerciseDate, fixedRate))
return( price )
}
|
