summaryrefslogtreecommitdiffstats
path: root/R/tranche_functions.R
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2014-08-20 16:48:10 -0400
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2014-08-20 16:48:10 -0400
commite3f29ddde286c4011590ad83916777b3e519f8c7 (patch)
treeb10916955b5c83f65e98dd53a8aba01949765368 /R/tranche_functions.R
parentc451841cdac4bef74ef9a011f13d8befe85e9d56 (diff)
downloadlossdistrib-e3f29ddde286c4011590ad83916777b3e519f8c7.tar.gz
add MFtranche.delta which mimics BCtranche.delta
Diffstat (limited to 'R/tranche_functions.R')
-rw-r--r--R/tranche_functions.R33
1 files changed, 33 insertions, 0 deletions
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)