diff options
Diffstat (limited to 'R/tranche_functions.R')
| -rw-r--r-- | R/tranche_functions.R | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/R/tranche_functions.R b/R/tranche_functions.R index d1052ef0..f7b3f730 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -190,23 +190,29 @@ adjust.skew <- function(index1, index2, method="ATM"){ K1 <- index1$K[-c(1,length(index1$K))] K2 <- index2$K[-c(1,length(index2$K))] + aux <- function(x, index1, el1, skew, index2, el2, K2){ - return(abs(ELtrunc(index1, x, skew(x))/el1- - ELtrunc(index2, K2, skew(x))/el2)) + newrho <- cap(skew(x)) + return(abs(ELtrunc(index1, x, newrho)/el1- + ELtrunc(index2, K2, newrho)/el2)) } + aux2 <- function(x, index1, skew, index2, K2){ - return(abs(log(Probtrunc(index1, x, skew(x)))- - log(Probtrunc(index2, K2, skew(x))))) + newrho <- cap(skew(x)) + return(abs(log(Probtrunc(index1, x, newrho))- + log(Probtrunc(index2, K2, newrho)))) } + if(method %in% c("ATM", "TLP")){ el1 <- EL(index1) el2 <- EL(index2) } - skew <- function(x){ - #we cap the correlation at 0.99 and 0.01 - f <- splinefun(K1, index1$rho[-c(1, length(index1$rho))], "natural") - return(pmax(pmin(f(x), 0.99), 0.01)) + + skew <- splinefun(K1, index1$rho[-c(1, length(index1$rho))], "natural") + cap <- function(x){ + pmax(pmin(skew(x), 0.99), 0.01) } + if(method=="ATM"){ K1eq <- el1/el2 * K2 }else if(method == "TLP"){ @@ -222,12 +228,12 @@ adjust.skew <- function(index1, index2, method="ATM"){ K1eq <- c() m <- max(K2) + 0.25 for(K2val in K2){ - prog <- optimize(aux2, interval=c(0, m), + prog <- optimize(aux2, interval=c(K2val*0.1, K2val*1.8), index1=index1, skew=skew, index2=index2, K2=K2val) K1eq <- c(K1eq, prog$minimum) } } - return(c(NA, skew(K1eq), NA)) + return(c(NA, cap(skew(K1eq)), NA)) } theta.adjust.skew <- function(index, shortened=4, method="ATM"){ @@ -241,12 +247,7 @@ theta.adjust.skew <- function(index, shortened=4, method="ATM"){ BCtranche.theta <- function(index, shortened=4, complement=FALSE, method="ATM"){ temp <- BCtranche.pv(index, complement=complement) - rho.adj <- theta.adjust.skew(index, shortened, method) - if(any(rho.adj[-c(1, length(rho.adj))]<=0)){ - print("probable inverted skew: no adjustment") - }else{ - index$rho <- rho.adj - } + index$rho <- theta.adjust.skew(index, shortened, method) N <- nrow(index$cs) - shortened index$cs <- index$cs[1:N,] index$defaultprob <- index$defaultprob[,1:N] |
