diff options
Diffstat (limited to 'tranche_functions.R')
| -rw-r--r-- | tranche_functions.R | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/tranche_functions.R b/tranche_functions.R index 3a5b568c..a7262ea0 100644 --- a/tranche_functions.R +++ b/tranche_functions.R @@ -279,7 +279,7 @@ tranche.cl <- function(L, R, cs, K1, K2, scaled=FALSE){ support <- seq(0, 1, length=n)
size <- K2 - K1 - crossprod(trancheloss(support, K1, K2), L) -
crossprod(trancherecov(support, K1, K2), R)
- sizeadj <-as.numeric(0.5 * (size + c(K2-K1, size[-length(size)])))
+ sizeadj <- as.numeric(0.5 * (size + c(K2-K1, size[-length(size)])))
if(scaled){
return( 1/(K2-K1) * crossprod(sizeadj * cs$coupons, cs$df) )
}else{
@@ -311,6 +311,8 @@ tranche.pv <- function(L, R, cs, K1, K2){ }
adjust.attachments <- function(K, losstodate, factor){
+ ## computes the attachments adjusted for losses
+ ## on current notional
return( pmin(pmax((K-losstodate)/factor, 0),1) )
}
@@ -385,15 +387,47 @@ BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, lu=0.01){ }
BCtranche.delta <- function(portfolio, index, coupon, K1, K2, rho1, rho2, lu=0.01){
- eps <- 1e-6
+ ## 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
+ ## this makes sense for bottom-up skews
+ eps <- 1e-4
portfolioplus <- portfolio
portfoliominus <- portfolio
for(i in 1:length(portfolio)){
- portfolioplus[[i]]@curve@hazardrates <- portfolioplus[[i]]@curve@hazardrates + eps
- portfoliominus[[i]]@curve@hazardrates <- portfoliominus[[i]]@curve@hazardrates - eps
+ portfolioplus[[i]]@curve@hazardrates <- portfolioplus[[i]]@curve@hazardrates * (1 + eps)
+ portfoliominus[[i]]@curve@hazardrates <- portfoliominus[[i]]@curve@hazardrates * (1- eps)
}
- dPVtranche <- BCtranche.pv(portfolioplus, index, coupon, K1, K2, rho1, rho2, lu)$bp -
- BCtranche.pv(portfoliominus, index, coupon, K1, K2, rho1, rho2, lu)$bp
- dPVindex <- indexpv(portfolioplus, index)-indexpv(portfoliominus, index)
- return( dPVtranche/(100*dPVindex))
+ dPVindex <- indexpv(portfolioplus, index) - indexpv(portfoliominus, index)
+ if(K2==1){
+ dPVtranche <- BCtranche.pv(portfolioplus, index, coupon, 0, K1, 0, rho1, lu)$bp -
+ BCtranche.pv(portfoliominus, index, coupon, 0, K1, 0, rho1, lu)$bp
+ K1adj <- adjust.attachments(K1, index$loss, index$factor)
+ delta <- (1 - dPVtranche/(100*dPVindex) * K1adj)/(1-K1adj)
+ }else{
+ dPVtranche <- BCtranche.pv(portfolioplus, index, coupon, K1, K2, rho1, rho2, lu)$bp -
+ BCtranche.pv(portfoliominus, index, coupon, K1, K2, rho1, rho2, lu)$bp
+ delta <- dPVtranche/(100*dPVindex)
+ }
+ ## 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 )
+}
+
+BCstrikes <- function(portfolio, index, coupon, K, rho) {
+ ## computes the strikes as a percentage of expected loss
+ EL <- c()
+ for(i in 2:length(K)){
+ EL <- c(EL, -BCtranche.pv(portfolio, index, coupon, K[i-1], K[i], rho[i-1], rho[i], lu)$pl)
+ }
+ Kmodified <- adjust.attachments(K, index$loss, index$factor)
+ return(cumsum(EL*diff(Kmodified))/sum(EL*diff(Kmodified)))
+}
+
+delta.factor <- function(K1, K2, index){
+ ## compute the factor to convert from delta on current notional to delta on original notional
+ ## K1 and K2 original strikes
+ factor <- (adjust.attachments(K2, index$loss, index$factor)
+ -adjust.attachments(K1, index$loss, index$factor))/(K2-K1)
+ return( factor )
}
|
