aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/calibrate_tranches_BC.R33
-rw-r--r--R/calibration.R6
2 files changed, 10 insertions, 29 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R
index e0e358d0..bb38681d 100644
--- a/R/calibrate_tranches_BC.R
+++ b/R/calibrate_tranches_BC.R
@@ -16,7 +16,7 @@ n.int <- 250
attach(GHquad(n.int))
Ngrid <- 201
-alldates <- seq(as.Date("2014-01-01"), as.Date("2014-05-30"), by="1 day")
+alldates <- seq(as.Date("2014-01-01"), as.Date("2014-01-05"), by="1 day")
rhomat <- c()
deltasmat <- c()
bus.dates <- as.Date(names(which(isBusinessDay(calendar="UnitedStates/GovernmentBond", alldates))))
@@ -30,40 +30,21 @@ for(i in seq_along(bus.dates)){
## calibrate the tranches using base correlation
f <- function(rho, index, N, i){
- temp <- with(index,
- BClossdistC(defaultprob, issuerweights, recov, rho, Z, w, N))
+ temp <- BClossdistC(index$defaultprob, index$issuerweights, index$recov, rho, Z, w, N)
return(abs(tranche.pv(temp$L, temp$R, index$cs, 0, index$K[i+1]) + index$quotes[i]))
}
rhovec <- c()
for(j in 1:(length(hy21$K)-1)){
+ ##q <- quotes[i-1]
rho <- optimize(f, interval=c(0,1), index=hy21, N=Ngrid, i=j)$minimum
rhovec <- c(rhovec, rho)
}
rhovec <- c(0, rhovec)
-
- ##compute deltas by blipping the curves
- ## portfolioplus <- tweakportfolio(hy21portfolio.tweaked, 1e-4)
- ## defaultprobplus <- 1 - SPmatrix(portfolioplus, length(cs$dates))
- ## portfoliominus <- tweakportfolio(hy21portfolio.tweaked, -1e-4)
- ## defaultprobminus <- 1 - SPmatrix(portfoliominus, length(cs$dates))
- ## test <- matrix(0, 6, 2)
- ## for(i in 2:7){
- ## tempminus <- BClossdistC(defaultprobminus, issuerweights, recov, rhovec[i], Z, w, Ngrid)
- ## tempplus <- BClossdistC(defaultprobplus, issuerweights, recov, rhovec[i], Z, w, Ngrid)
- ## test[i-1,1] <- tranche.pv(tempminus$L, tempminus$R, cs, 0, Kmodified[i])
- ## test[i-1,2] <- tranche.pv(tempplus$L, tempplus$R, cs, 0, Kmodified[i])
- ## }
- ## dPVtranche <- diff(c(0, test[,1]))/dK - diff(c(0, test[,2]))/dK
- ## dPVindex <- indexpv(portfoliominus, hy21, tradedate=tradedate, clean=FALSE)$bp-
- ## indexpv(portfolioplus, hy21, tradedate=tradedate, clean=FALSE)$bp
- ## deltas <- dPVtranche/dPVindex
-
- ##use BCtranche.delta function
- deltas <- rep(0, length(hy21$K)-1)
- for(j in seq_along(hy21$K[-1])){
- deltas[j] <- BCtranche.delta(hy21, hy21$K[j], hy21$K[j+1], rhovec[j], rhovec[j+1], Z, w, Ngrid, tradedate)
- }
+ hy21$rho <- rhovec
+ deltas <- BCtranche.delta(hy21, Z, w, Ngrid, tradedate)
deltasmat <- rbind(deltasmat, deltas)
rhomat <- rbind(rhomat, rhovec)
cat(i, "\n")
}
+write.csv(deltasmat, file="delta.csv")
+write.csv(rhomat, file="rho.csv")
diff --git a/R/calibration.R b/R/calibration.R
index 96bf03f2..469fe9db 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -32,7 +32,7 @@ set.singlenamesdata <- function(index, tradedate){
paste0(index.name, "_singlenames_", tradedate, ".csv")))
nondefaulted <- singlenames.data[!singlenames.data$ticker %in% index$defaulted,]
cds.cs <- get.cdsSchedule(tradedate)
- index$portfolio <- c()
+ index$portfolio <- list()
for(i in 1:nrow(nondefaulted)){
index$portfolio <- c(index$portfolio, buildSC(nondefaulted[i,], cds.cs$cs, cds.cs$cdsdates))
}
@@ -48,8 +48,8 @@ set.tranchedata <- function(index, tradedate){
index$indexref <- index$tranche.data$bidRefPrice[1]/100
index$cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", 0.05, 0, tradedate,
IMMDate(tradedate, "prev"))
- index$portfolio.tweaked <- tweakcurves(index, tradedate)$portfolio
- index$defaultprob <- 1-SPmatrix(index$portfolio.tweaked, length(index$cs$dates))
+ index$portfolio <- tweakcurves(index, tradedate)$portfolio
+ index$defaultprob <- 1-SPmatrix(index$portfolio, length(index$cs$dates))
K <- c(0, 0.15, 0.25, 0.35, 1)
index$K <- adjust.attachments(K, index$loss, index$factor)
index$tranche.upf <- index$tranche.data$Mid