diff options
Diffstat (limited to 'R/calibrate_tranches_BC.R')
| -rw-r--r-- | R/calibrate_tranches_BC.R | 33 |
1 files changed, 7 insertions, 26 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")
|
