From c451841cdac4bef74ef9a011f13d8befe85e9d56 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 20 Aug 2014 16:47:44 -0400 Subject: replace tranche.pvvec with MFtranche.pv, which mimics BCtranche.pv --- R/tranche_functions.R | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'R/tranche_functions.R') diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 9b971f2..6bff635 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -610,14 +610,6 @@ adjust.attachments <- function(K, losstodate, factor){ return( pmin(pmax((K-losstodate)/factor, 0),1) ) } -tranche.pvvec <- function(K, L, R, cs){ - r <- rep(0, length(K)-1) - for(i in 1:(length(K)-1)){ - r[i] <- 1/(K[i+1]-K[i]) * tranche.pv(L, R, cs, K[i], K[i+1]) - } - return( r ) -} - BClossdist <- function(defaultprob, issuerweights, recov, rho, Z, w, N=length(recov)+1, defaultflag=FALSE, n.int=500){ if(missing(Z)){ @@ -702,6 +694,25 @@ BCtranche.pv <- function(index, protection=FALSE, complement=FALSE){ return(list(pl=plvec, cl=clvec, bp=bp)) } +MFtranche.pv <- function(index, dist, protection=FALSE){ + n.tranches <- length(index$K)-1 + pl <- rep(0, n.tranches) + cl <- rep(0, n.tranches) + for(i in seq.int(n.tranches)){ + pl[i] <- tranche.pl(dist$L, index$cs, index$K[i], index$K[i+1]) + cl[i] <- tranche.cl(dist$L, dist$R, index$cs, index$K[i], index$K[i+1]) + } + dK <- diff(index$K) + plvec <- pl/dK + clvec <- cl/dK*index$tranche.running + if(protection){ + bp <- -plvec-clvec + }else{ + bp <- 1+plvec+clvec + } + return(list(pl=plvec, cl=clvec, bp=bp)) +} + adjust.skew <- function(index1, index2, method="ATM"){ #index1 is the index for which we already have computed the skew #index2 is the index we're mapping to -- cgit v1.2.3-70-g09d2