diff options
| -rw-r--r-- | R/calibrate_tranches_BC.R | 27 | ||||
| -rw-r--r-- | R/calibration.R | 24 |
2 files changed, 28 insertions, 23 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R index 9d0867f5..21574d64 100644 --- a/R/calibrate_tranches_BC.R +++ b/R/calibrate_tranches_BC.R @@ -16,12 +16,8 @@ n.int <- 250 list2env(GHquad(n.int), envir=parent.frame())
Ngrid <- 201
-aux <- function(rho, index, K, quote, spread){
- temp <- BCtranche.legs(index, K, rho)
- return(abs(temp$pl+temp$cl*spread + quote))
-}
+#parse command line arguments
args <- commandArgs(trailingOnly=TRUE)
-
index.name <- args[1]
if(length(args)>=2&&args[2]!="update"){
tenor <- args[2]
@@ -42,8 +38,7 @@ if(updateflag){##ghetto way of getting the last row of the file hy21 = as.Date("2013-10-04"),
ig9 = as.Date("2013-01-01"),
ig19 = as.Date("2013-05-01"),
- ig21 = as.Date("2013-09-26"),
- )
+ ig21 = as.Date("2013-09-26"))
}
alldates <- seq(begin.date, Sys.Date()-1, by="1 day")
@@ -93,22 +88,7 @@ for(i in seq_along(bus.dates)){ indexEL[i] <- EL(index)
indexTheta[i] <- indextheta(index, tradedate)
## calibrate the tranches using base correlation
- rhovec <- c(0)
- for(j in 1:(length(index$K)-2)){
- ##use the current tranche coupon
- ## we compute the 0-index$K[j+1] equivalent quote using the coupon of the jth quote
- if(j==1){
- q <- index$tranche.quotes[j]*index$K[j+1]
- }else{
- temp <- BCtranche.legs(index, index$K[j], rhovec[j])
- q <- index$tranche.quotes[j] * (index$K[j+1]-index$K[j])-
- temp$pl - temp$cl*index$tranche.running[j]
- }
- rho <- optimize(aux, interval=c(0,1), index=index, K=index$K[j+1], quote=q,
- spread=index$tranche.running[j])$minimum
- rhovec <- c(rhovec, rho)
- }
- index$rho <- c(rhovec, NA)
+ index$rho <- build.skew(index)
temp <- BCtranche.delta(index, tradedate)
deltas[i,] <- temp$deltas
gammas[i,] <- temp$gammas
@@ -120,6 +100,7 @@ for(i in seq_along(bus.dates)){ ELmat[i,] <- -temp$pl*diff(index$K)
print(tradedate)
}
+
risk.numbers <- data.frame(deltas, gammas, thetas, rhos, corr01, durations, EL)
colnames(risk.numbers) <- c(paste(tranche.names, "Model Delta"),
paste(tranche.names, "Gamma"),
diff --git a/R/calibration.R b/R/calibration.R index 762c3a53..ca9f9b9e 100644 --- a/R/calibration.R +++ b/R/calibration.R @@ -86,3 +86,27 @@ set.tranchedata <- function(index, tradedate){ } return( index ) } + +build.skew <- function(index){ + require(lossdistrib) + aux <- function(rho, index, K, quote, spread){ + temp <- BCtranche.legs(index, K, rho) + return(abs(temp$pl+temp$cl*spread + quote)) + } + rhovec <- c(0) + for(j in 1:(length(index$K)-2)){ + ##use the current tranche coupon + ## we compute the 0-index$K[j+1] equivalent quote using the coupon of the jth quote + if(j==1){ + q <- index$tranche.quotes[j]*index$K[j+1] + }else{ + temp <- BCtranche.legs(index, index$K[j], rhovec[j]) + q <- index$tranche.quotes[j] * (index$K[j+1]-index$K[j])- + temp$pl - temp$cl*index$tranche.running[j] + } + rho <- optimize(aux, interval=c(0,1), index=index, K=index$K[j+1], quote=q, + spread=index$tranche.running[j])$minimum + rhovec <- c(rhovec, rho) + } + return( c(rhovec, NA) ) +} |
