aboutsummaryrefslogtreecommitdiffstats
path: root/tranche_functions.R
diff options
context:
space:
mode:
Diffstat (limited to 'tranche_functions.R')
-rw-r--r--tranche_functions.R30
1 files changed, 28 insertions, 2 deletions
diff --git a/tranche_functions.R b/tranche_functions.R
index 3c41d45f..b1d11b13 100644
--- a/tranche_functions.R
+++ b/tranche_functions.R
@@ -1,5 +1,17 @@
library(statmod)
+## todo:
+## -investigate other ways to interpolate the random severities on the grid
+## I'm thinking that at eah severity that we add to the distribution, round it down
+## and keep track of the missing mass: namely if X_i=S_i w.p p_i, then add
+## X_i=lu*floor(S_i/lu) with probability p_i and propagate
+## X_{i+1}=S_{i+1}+(S_i-lu*floor(S_i/lu)) with the right probability
+## - investigate truncated distributions more (need to compute loss and recov distribution
+## separately, for the 0-10 equity tranche, we need the loss on the 0-0.1 support and
+## recovery with 0.1-1 support, so it's not clear that there is a big gain.
+## - do the correlation adjustments when computing the deltas since it seems to be
+## the market standard
+
lossdistrib <- function(p){
## basic recursive algorithm of Andersen, Sidenius and Basu
n <- length(p)
@@ -310,6 +322,8 @@ trancherecov <- function(R, K1, K2){
tranche.cl <- function(L, R, cs, K1, K2, Ngrid=nrow(L), scaled=FALSE){
## computes the couponleg of a tranche
## if scaled is TRUE, scale it by the size of the tranche (K2-K1)
+ ## can make use of the fact that the loss and recov distribution are
+ ## truncated (in that case nrow(L) != Ngrid
if(K1==K2){
return( 0 )
}else{
@@ -398,7 +412,7 @@ BClossdistC <- function(SurvProb, issuerweights, recov, rho,
return(list(L=r$L,R=r$R))
}
-BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=101){
+BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=length(portfolio)+1){
## computes the protection leg, couponleg, and bond price of a tranche
## in the base correlation setting
if(K1==0){
@@ -424,7 +438,7 @@ BCtranche.pv <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=101){
bp=100*(1+(pl2-pl1+cl2-cl1)/dK)))
}
-BCtranche.delta <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=101){
+BCtranche.delta <- function(portfolio, index, coupon, K1, K2, rho1, rho2, N=length(portolio)+1){
## 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
@@ -469,3 +483,15 @@ delta.factor <- function(K1, K2, index){
-adjust.attachments(K1, index$loss, index$factor))/(K2-K1)
return( factor )
}
+
+MFupdate.prob <- function(Z, w, rho, defaultprob){
+ ## update the probabilites based on a non gaussian factor
+ ## distribution so that the pv of the cds stays the same.
+ p <- matrix(0, nrow(defaultprob), ncol(defaultprob))
+ for(i in 1:nrow(defaultprob)){
+ for(j in 1:ncol(defaultprob)){
+ p[i,j] <- fit.prob(Z, program$weight, rho, defaultprob[i,j])
+ }
+ }
+ return( p )
+}