aboutsummaryrefslogtreecommitdiffstats
path: root/R/calibrate_tranches.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/calibrate_tranches.R')
-rw-r--r--R/calibrate_tranches.R71
1 files changed, 26 insertions, 45 deletions
diff --git a/R/calibrate_tranches.R b/R/calibrate_tranches.R
index 55315587..52802685 100644
--- a/R/calibrate_tranches.R
+++ b/R/calibrate_tranches.R
@@ -27,25 +27,6 @@ for(tenor in paste0(1:5, "y")){
cdsdates <- c(cdsdates, cdsMaturity(tenor))
}
-## clusterEvalQ(cl, {setClass("abstractcurve")
-## setClass("defaultcurve", contains="abstractcurve",
-## representation(dates="Date", hazardrates="numeric"))
-## setClass("creditcurve", representation(issuer="character", startdate="Date",
-## recovery="numeric", curve="defaultcurve"))})
-## clusterExport(cl, list("nondefaulted", "cdsdates", "cdshazardrate", "today",
-## "bps", "couponSchedule", "nextIMMDate", "DiscountCurve", "L3m"))
-## test <- parSapply(cl, 1:nrow(nondefaulted), parf)
-
-## parf <- function(i){
-## SC <- new("creditcurve",
-## recovery=nondefaulted$recovery[i]/100,
-## startdate=today(),
-## issuer=as.character(nondefaulted$ticker[i]))
-## quotes <- data.frame(maturity=cdsdates, upfront = as.numeric(nondefaulted[i,5:9])*0.01,
-## running = rep(nondefaulted$running[i]*bps,5))
-## return( cdshazardrate(quotes, nondefaulted$recovery[i]/100))
-## }
-
hy19portfolio <- c()
for(i in 1:nrow(nondefaulted)){
SC <- new("creditcurve",
@@ -59,43 +40,20 @@ for(i in 1:nrow(nondefaulted)){
}
issuerweights <- rep(1/length(hy19portfolio), length(hy19portfolio))
-hy19$indexref <- 1.025
+hy19$indexref <- 1.0275
hy19portfolio.tweaked <- tweakcurves(hy19portfolio, hy19)
SurvProb <- SPmatrix(hy19portfolio.tweaked, hy19)
## load common parameters
K <- c(0, 0.15, 0.25, 0.35, 1)
Kmodified <- adjust.attachments(K, hy19$loss, hy19$factor)
-tranche.upf <- c(42.25, 95.375, 108.28125, 116.8125)
+tranche.upf <- c(43.375, 95.125, 108.25, 116.8125)
tranche.running <- c(0.05, 0.05, 0.05, 0.05)
-Ngrid <- 2*nrow(nondefaulted)+1
+Ngrid <- 2 * nrow(nondefaulted)+1
recov <- sapply(hy19portfolio.tweaked, attr, "recovery")
cs <- couponSchedule(nextIMMDate(today()), hy19$maturity,"Q", "FIXED", 0.05, 0)
-## calibrate the tranches using base correlation
-rhovec <- c()
-f <- function(rho, ...){
- temp <- BClossdistC(SurvProb, issuerweights, recov, rho, Ngrid)
- bp <- 100*(1+1/(Kmodified[i]-Kmodified[i-1]) *
- (tranche.pv(temp$L, temp$R, cs, 0, Kmodified[i], Ngrid) -
- tranche.pv(oldtemp$L, oldtemp$R, cs, 0, Kmodified[i-1], Ngrid)))
- return( abs(tranche.upf[i-1]-bp))
-}
-
-for(i in 2:length(Kmodified)){
- rho <- optimize(f, interval=c(0,1),
- SurvProb, issuerweights, recov, Ngrid, tranche.upf, Kmodified, cs, oldtemp)$minimum
- oldtemp <- BClossdistC(SurvProb, issuerweights, recov, rho, Ngrid)
- rhovec <- c(rhovec, rho)
-}
-
-rhovec <- c(0, rhovec)
-deltas <- c()
-for(i in 2:5){
- deltas <- c(deltas, BCtranche.delta(hy19portfolio.tweaked, hy19, 0.05, K[i-1], K[i], rhovec[i-1], rhovec[i], Ngrid))
-}
-
##calibrate by modifying the factor distribution
bottomup <- 1:3
topdown <- 2:4
@@ -155,6 +113,29 @@ for(l in 1:100){
write.table(data.frame(Z=Z, w=w.mod), file=file.path(root.dir, "Scenarios", "Calibration", paste0("calibration-", Sys.Date(), ".csv")), col.names=T, row.names=F, sep=",")
save(singlenames.data, hy19, tranche.upf, file = file.path(root.dir, "Scenarios", "Calibration", paste0("marketdata-", Sys.Date(), ".RData")))
+## calibrate the tranches using base correlation
+rhovec <- c()
+f <- function(rho, ...){
+ temp <- BClossdistC(SurvProb, issuerweights, recov, rho, Ngrid)
+ bp <- 100*(1+1/(Kmodified[i]-Kmodified[i-1]) *
+ (tranche.pv(temp$L, temp$R, cs, 0, Kmodified[i], Ngrid) -
+ tranche.pv(oldtemp$L, oldtemp$R, cs, 0, Kmodified[i-1], Ngrid)))
+ return( abs(tranche.upf[i-1]-bp))
+}
+
+for(i in 2:length(Kmodified)){
+ rho <- optimize(f, interval=c(0,1),
+ SurvProb, issuerweights, recov, Ngrid, tranche.upf, Kmodified, cs, oldtemp)$minimum
+ oldtemp <- BClossdistC(SurvProb, issuerweights, recov, rho, Ngrid)
+ rhovec <- c(rhovec, rho)
+}
+
+rhovec <- c(0, rhovec)
+deltas <- c()
+for(i in 2:5){
+ deltas <- c(deltas, BCtranche.delta(hy19portfolio.tweaked, hy19, 0.05, K[i-1], K[i], rhovec[i-1], rhovec[i], Ngrid))
+}
+
## computes MFdeltas
newportf <- hy19portfolio.tweaked
eps <- 1e-4