summaryrefslogtreecommitdiffstats
path: root/R/tranche_functions.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/tranche_functions.R')
-rw-r--r--R/tranche_functions.R29
1 files changed, 14 insertions, 15 deletions
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index 8d7ab04..8b8b263 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -679,8 +679,7 @@ BCtranche.pv <- function(index, K1, K2, rho1, rho2,
bp=100*(1+(pl2-pl1+cl2-cl1)/dK)))
}
-BCtranche.delta <- function(index, K1, K2, rho1, rho2, Z, w,
- N=length(portolio)+1, tradedate = Sys.Date()){
+BCtranche.delta <- function(index, Z, w, N=length(portolio)+1, tradedate = Sys.Date()){
## computes the tranche delta (on current notional) by doing a proportional
## blip of all the curves
## if K2==1, then computes the delta using the lower attachment only
@@ -697,20 +696,20 @@ BCtranche.delta <- function(index, K1, K2, rho1, rho2, Z, w,
indexminus$defaultprob <- 1 - SPmatrix(Portf.minus, length(index$cs$dates))
dPVindex <- indexpv(indexplus, tradedate = tradedate, clean = FALSE)$bp -
indexpv(indexminus, tradedate = tradedate, clean = FALSE)$bp
- if(K2==1){
- K1adj <- adjust.attachments(K1, index$loss, index$factor)
- dPVtranche <- BCtranche.pv(indexplus, 0, K1adj, 0, rho1, Z, w, N)$bp -
- BCtranche.pv(indexminus, 0, K1adj, 0, rho1, Z, w, N)$bp
- delta <- (1 - dPVtranche/(100*dPVindex) * K1adj)/(1-K1adj)
- }else{
- Kmod <- adjust.attachments(c(K1, K2), index$loss, index$factor)
- dPVtranche <- BCtranche.pv(indexplus, Kmod[1], Kmod[2], rho1, rho2, Z, w, N)$bp -
- BCtranche.pv(indexminus, Kmod[1], Kmod[2], rho1, rho2, Z, w, N)$bp
- delta <- dPVtranche/(100*dPVindex)
+ deltas <- rep(0, length(index$K)-1)
+ bpplus <- c(0)
+ bpminus <- c(0)
+ for(i in 1:(length(index$rho)-2)){
+ distplus <- BClossdistC(indexplus$defaultprob, index$issuerweights, index$recov, index$rho[i+1], Z, w, N)
+ distminus <- BClossdistC(indexminus$defaultprob, index$issuerweights, index$recov, index$rho[i+1], Z, w, N)
+ bpplus <- c(bpplus, tranche.pv(distplus$L, distplus$R, index$cs, 0, index$K[i+1]))
+ bpminus <- c(bpminus, tranche.pv(distminus$L, distminus$R, index$cs, 0, index$K[i+1]))
}
- ## dPVindex <- BCtranche.pv(portfolioplus, index, coupon, 0, 1, 0, 0.5, lu)$bp-
- ## BCtranche.pv(portfoliominus, index, coupon, 0, 1, 0, 0.5, lu)$bp
- return( delta )
+ dPVtranche <- 1/diff(index$K[-length(index$K)])*(diff(bpplus) - diff(bpminus))
+ deltas <- dPVtranche/dPVindex
+ deltas <- c(deltas,
+ (1-(bpplus[length(bpplus)]-bpminus[length(bpminus)])/dPVindex)/(1-index$K[length(index$K)-1]))
+ return( deltas )
}
EL <- function(index){