aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/calibrate_tranches_BC.R11
1 files changed, 6 insertions, 5 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R
index c50f3149..69298f13 100644
--- a/R/calibrate_tranches_BC.R
+++ b/R/calibrate_tranches_BC.R
@@ -18,6 +18,11 @@ Ngrid <- 201
alldates <- seq(as.Date("2014-01-01"), as.Date("2014-01-05"), by="1 day")
+aux <- function(rho, index, N, i){
+ 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]))
+}
+
bus.dates <- as.Date(names(which(isBusinessDay(calendar="UnitedStates/GovernmentBond", alldates))))
for(index.name in c("hy19", "hy21"){
rhomat <- c()
@@ -32,13 +37,9 @@ for(index.name in c("hy19", "hy21"){
index <- set.tranchedata(index, tradedate)
## calibrate the tranches using base correlation
- f <- function(rho, index, N, i){
- 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(index$K)-1)){
- rho <- optimize(f, interval=c(0,1), index=index, N=Ngrid, i=j)$minimum
+ rho <- optimize(aux, interval=c(0,1), index=index, N=Ngrid, i=j)$minimum
rhovec <- c(rhovec, rho)
}
rhovec <- c(0, rhovec)