diff options
| -rw-r--r-- | R/calibration.R | 14 | ||||
| -rw-r--r-- | R/cds_functions_generic.R | 4 |
2 files changed, 10 insertions, 8 deletions
diff --git a/R/calibration.R b/R/calibration.R index 98460489..7caec58f 100644 --- a/R/calibration.R +++ b/R/calibration.R @@ -57,7 +57,7 @@ set.tranchedata <- function(index, tradedate){ } index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity,"Q", "FIXED", 1, 0, tradedate, IMMDate(tradedate, "prev")) - if(!is.na(temp$indexrefprice[1])&&temp$indexrefprice[1]!=0){ + if(!is.na(temp$indexrefprice[1]) && temp$indexrefprice[1] != 0){ index$quotes$price <- temp$indexrefprice[1]/100 }else{ ##rewrite as a snac function @@ -67,22 +67,24 @@ set.tranchedata <- function(index, tradedate){ defaultleg(index$cs, sc, index$recovery, startdate) index$quotes$price <- 1 + cds.pv - cdsAccrued(tradedate, index$quotes$spread[1]) } - index$portfolio <- tweakcurves(index, tradedate)$portfolio + tweak <- tweakcurves(index, tradedate) + index$portfolio <- NULL + index <- c(index, tweak) index$defaultprob <- 1 - SPmatrix(index$portfolio, length(index$cs$dates)) negprob <- which(index$defaultprob<0, arr.ind=T) - if(nrow(negprob)>0){ + if(nrow(negprob) > 0){ stop(paste(index$portfolio[[negprob[1,1]]]@issuer, "has negative probability, check single names data")) } 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 + index$tranche.running <- temp$trancherunningmid * 1e-4 ## compute dirty protection price if(length(grep("hy", index$name, ignore.case=TRUE))>0){ - index$tranche.quotes <- 1-index$tranche.upf/100-cdsAccrued(tradedate, index$tranche.running) + index$tranche.quotes <- 1 - index$tranche.upf/100 - cdsAccrued(tradedate, index$tranche.running) }else{ - index$tranche.quotes <- index$tranche.upf/100-cdsAccrued(tradedate, index$tranche.running) + index$tranche.quotes <- index$tranche.upf/100 - cdsAccrued(tradedate, index$tranche.running) } return( index ) } diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index f1aa7179..d6623bd0 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -640,9 +640,9 @@ tweakcurves <- function(index, tradedate=Sys.Date()){ }
epsilon[i] <- optimize(f, c(-0.15, 0.15), index, tol=1e-6)$minimum
index$portfolio <- tweakportfolio(index$portfolio, epsilon[i], forward.tweak=forward.tweak)
+ cat("tweak = ", epsilon[i], "\n")
}
- cat("tweak = ", epsilon, "\n")
- return( list(portfolio=index$portfolio, epsilon=epsilon) )
+ return( list(portfolio=index$portfolio, basis=epsilon) )
}
survivalProbability1 <- function(startdate, date, survival.curve) {
|
