aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/calibrate_tranches_BC.R31
1 files changed, 16 insertions, 15 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R
index 319bfb7b..a606528e 100644
--- a/R/calibrate_tranches_BC.R
+++ b/R/calibrate_tranches_BC.R
@@ -4,11 +4,9 @@ if(.Platform$OS.type == "unix"){
root.dir <- "//WDSENTINEL/share/CorpCDOs"
}
-source(file.path(root.dir, "code", "R", "cds_utils.R"))
-source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
source(file.path(root.dir, "code", "R", "yieldcurve.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
-source(file.path(root.dir, "code", "R", "calibration.R"))
+source(file.path(root.dir, "code", "R", "calibration.R"), chdir=TRUE)
source(file.path(root.dir, "code", "R", "mlpdb.R"))
library(lossdistrib)
@@ -16,18 +14,17 @@ n.int <- 250
list2env(GHquad(n.int), envir=parent.frame())
Ngrid <- 201
-alldates <- seq(as.Date("2014-03-04"), as.Date("2014-01-05"), by="1 day")
-
aux <- function(rho, index, K, quote, spread){
temp <- BCtranche.legs(index, K, rho)
return(abs(temp$pl+temp$cl*spread + quote))
}
+alldates <- seq(as.Date("2014-01-01"), as.Date("2014-06-10"), by="1 day")
bus.dates <- as.Date(names(which(isBusinessDay(calendar="UnitedStates/GovernmentBond", alldates))))
-for(index.name in c("hy19", "hy21", "ig19", "ig21")){
- rhomat <- c()
- deltasmat <- c()
- gammasmat <- c()
+quotes <- matrix(0, length(bus.dates), 5)
+for(index.name in c("hy21")){
+ risk.numbers <- list(rho=c(), delta=c(), gamma=c(), theta=c())
+ i.theta <- c()
for(i in seq_along(bus.dates)){
tradedate <- bus.dates[i]
exportYC(tradedate)
@@ -35,6 +32,9 @@ for(index.name in c("hy19", "hy21", "ig19", "ig21")){
## calibrate the single names curves
index <- set.singlenamesdata(index, tradedate)
index <- set.tranchedata(index, tradedate)
+ temp <- get.tranchequotes(index$name, index$tenor, tradedate)
+ quotes[i,-5] <- temp$trancheupfront
+ quotes[i, 5] <- temp$indexrefprice[1]
## calibrate the tranches using base correlation
rhovec <- c(0)
for(j in 1:(length(index$K)-1)){
@@ -53,13 +53,14 @@ for(index.name in c("hy19", "hy21", "ig19", "ig21")){
}
index$rho <- rhovec
temp <- BCtranche.delta(index, tradedate)
- deltasmat <- rbind(deltasmat, temp$deltas)
- gammasmat <- rbind(gammasmat, temp$gammas)
-
- temp <- BCtranche.pv(index)
+ risk.numbers$delta <- rbind(risk.numbers$delta, temp$deltas)
+ risk.numbers$gamma <- rbind(risk.numbers$gamma, temp$gammas)
+ risk.numbers$theta <- rbind(risk.numbers$theta, BCtranche.theta(index))
+ risk.numbers$rho <- rbind(risk.numbers$rho, rhovec)
+ i.theta <- c(i.theta, indextheta(index, tradedate))
+ temp <- BCtranche.pv(index, protection=TRUE)
duration <- (temp$cl-cdsAccrued(tradedate, index$tranche.running))/index$tranche.running
- rhomat <- rbind(rhomat, rhovec)
+ risk.numbers$duration <- rbind(risk.numbers$duration, duration)
cat(i, "\n")
}
- assign(index.name, index)
}