diff options
Diffstat (limited to 'R/calibration.R')
| -rw-r--r-- | R/calibration.R | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/R/calibration.R b/R/calibration.R index 7caec58f..be3c3a40 100644 --- a/R/calibration.R +++ b/R/calibration.R @@ -51,7 +51,9 @@ set.singlenamesdata <- function(index, tradedate){ set.tranchedata <- function(index, tradedate){ temp <- get.tranchequotes(index$name, index$tenor, tradedate) - index$quotes <- data.frame(spread=temp$indexrefspread[1]*1e-4, maturity=index$maturity) + index$quotes <- data.frame(spread=temp$indexrefspread[1]*1e-4, + maturity=index$maturity, + ref=temp$indexrefprice[1]) if(index$name=="ig19" || index$name=="ig21"){ index$quotes$spread <- 0.01 } @@ -78,14 +80,20 @@ set.tranchedata <- function(index, tradedate){ K <- c(0, temp$detach/100) index$K.orig <- K index$K <- adjust.attachments(K, index$loss, index$factor) - index$tranche.upf <- temp$trancheupfrontmid - index$tranche.running <- temp$trancherunningmid * 1e-4 + ## compute dirty protection price + accrued <- cdsAccrued(tradedate, temp$trancherunningmid*1e-4) if(length(grep("hy", index$name, ignore.case=TRUE))>0){ - index$tranche.quotes <- 1 - index$tranche.upf/100 - cdsAccrued(tradedate, index$tranche.running) + dirtyquotes <- 1 - temp$trancheupfrontmid/100 - accrued }else{ - index$tranche.quotes <- index$tranche.upf/100 - cdsAccrued(tradedate, index$tranche.running) + dirtyquotes <- temp$trancheupfrontmid/100 - accrued } + index$tranches <- data.frame(upfront=temp$trancheupfrontmid, + running=temp$trancherunningmid * 1e-4, + quotes=dirtyquotes, + mkt.delta=temp$tranchedelta, + row.names=paste(index$K.orig[-length(index$K.orig)]*100, + index$K.orig[-1]*100, sep="-")) return( index ) } @@ -102,19 +110,19 @@ build.skew <- function(index, type="bottomup"){ ##use the current tranche coupon ## we compute the 0-index$K[j+1] equivalent quote using the coupon of the jth quote tranchepv <- BCtranche.legs(index, index$K[j], rhovec[j]) - q <- index$tranche.quotes[j] * dK[j] - - tranchepv$pl - tranchepv$cl*index$tranche.running[j] + q <- index$tranches$quotes[j] * dK[j] - + tranchepv$pl - tranchepv$cl*index$tranches$running[j] rho <- optimize(aux, interval=c(0,1), index=index, K=index$K[j+1], quote=q, - spread=index$tranche.running[j], complement=FALSE)$minimum + spread=index$tranches$running[j], complement=FALSE)$minimum rhovec[j+1] <- rho } }else if(type=="topdown"){ for(j in length(dK):2){ tranchepv <- BCtranche.legs(index, index$K[j+1], rhovec[j+1], complement=TRUE) q <- index$tranche.quotes[j] * dK[j] - - tranchepv$pl - tranchepv$cl * index$tranche.running[j] + tranchepv$pl - tranchepv$cl * index$tranches$running[j] rho <- optimize(aux, interval=c(0,1), index=index, K=index$K[j], quote=q, - spread=index$tranche.running[j], complement=TRUE)$minimum + spread=index$tranches$running[j], complement=TRUE)$minimum rhovec[j] <- rho } } |
