From e3f29ddde286c4011590ad83916777b3e519f8c7 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 20 Aug 2014 16:48:10 -0400 Subject: add MFtranche.delta which mimics BCtranche.delta --- R/tranche_functions.R | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'R/tranche_functions.R') diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 6bff635..787d64a 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -820,6 +820,39 @@ BCtranche.delta <- function(index, complement=FALSE){ return( list(deltas=deltas, gammas=gammas) ) } +MFtranche.delta <- function(index){ + ## computes the tranche delta (on current notional) by doing a proportional + ## blip of all the curves + ## if complement is False, then computes deltas bottom-up + ## if complement is True, then computes deltas top-down + eps <- 1e-4 + index$Ngrid <- 301 ## for gamma computations we need all the precision we can get + ## we build a lit of 4 indices with various shocks + index.list <- lapply(c(0, eps, -eps, 2*eps), function(x){ + if(x==0){ + return(index) + }else{ + newindex <- index + newindex$portfolio <- tweakportfolio(newindex$portfolio, x) + newindex$defaultprob <- 1 - SPmatrix(newindex$portfolio, length(index$cs$dates)) + return(newindex) + } + }) + bp <- matrix(0, length(index$K)-1, length(index.list)) + indexbp <- rep(0, length(index.list)) + for(j in seq_along(index.list)){ + indexbp[j] <- BCindex.pv(index.list[[j]])$bp + dist <- MFdist(index.list[[j]]) + bp[,j] <- BCtranche.pv(index.list[[j]], dist) + } + + deltas <- (bp[,2]-bp[,3])/(indexbp[2]-indexbp[3])*tranche.factor(index)/index$factor + deltasplus <- (bp[,4]-bp[,1])/(indexbp[4]-indexbp[1])*tranche.factor(index)/index$factor + gammas <- (deltasplus-deltas)/(indexbp[2]-indexbp[1])/100 + + return( list(deltas=deltas, gammas=gammas) ) +} + BCtranche.corr01 <- function(index, eps=0.01, complement=FALSE){ ##does a parallel shift of the skew and computes the change in pv before <- BCtranche.pv(index, complement=complement) -- cgit v1.2.3-70-g09d2