From 32ae9d261ea443c1905a0b4a0d36b8446824f161 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Thu, 29 May 2014 16:55:36 -0400 Subject: fix BCtranche.delta uses new api --- R/tranche_functions.R | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'R') diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 5764281..8d7ab04 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -679,38 +679,33 @@ BCtranche.pv <- function(index, K1, K2, rho1, rho2, bp=100*(1+(pl2-pl1+cl2-cl1)/dK))) } -BCtranche.delta <- function(portfolio, index, coupon, K1, K2, rho1, rho2, Z, w, +BCtranche.delta <- function(index, K1, K2, rho1, rho2, Z, w, N=length(portolio)+1, tradedate = Sys.Date()){ ## 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 - cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", coupon, 0, tradedate, - IMMDate(tradedate, "prev")) - for(i in 1:length(portfolio)){ - portfolioplus[[i]]@curve@hazardrates <- portfolioplus[[i]]@curve@hazardrates * (1 + eps) - portfoliominus[[i]]@curve@hazardrates <- portfoliominus[[i]]@curve@hazardrates * (1- eps) - } - dPVindex <- indexpv(portfolioplus, index, tradedate = tradedate, clean = FALSE)$bp - - indexpv(portfoliominus, index, tradedate = tradedate, clean = FALSE)$bp - defaultprobplus <- 1 - SPmatrix(portfolioplus, length(cs$dates)) - defaultprobminus <- 1 - SPmatrix(portfoliominus, length(cs$dates)) + + Portf.plus <- tweakportfolio(index$portfolio, eps) + Portf.minus <- tweakportfolio(index$portfolio, -eps) + indexplus <- index + indexplus$portfolio <- Portf.plus + indexplus$defaultprob <- 1 - SPmatrix(Portf.plus, length(index$cs$dates)) + indexminus <- index + indexminus$portfolio <- Portf.minus + indexminus$defaultprob <- 1 - SPmatrix(Portf.minus, length(index$cs$dates)) + dPVindex <- indexpv(indexplus, tradedate = tradedate, clean = FALSE)$bp - + indexpv(indexminus, tradedate = tradedate, clean = FALSE)$bp if(K2==1){ K1adj <- adjust.attachments(K1, index$loss, index$factor) - dPVtranche <- BCtranche.pv(defaultprobplus, issuerweights, recov, cs, 0, K1adj, 0, rho1, - Z, w, N)$bp - - BCtranche.pv(defaultprobminus, issuerweights, recov, cs, 0, K1adj, 0, rho1, - Z, w, N)$bp + dPVtranche <- BCtranche.pv(indexplus, 0, K1adj, 0, rho1, Z, w, N)$bp - + BCtranche.pv(indexminus, 0, K1adj, 0, rho1, Z, w, N)$bp delta <- (1 - dPVtranche/(100*dPVindex) * K1adj)/(1-K1adj) }else{ Kmod <- adjust.attachments(c(K1, K2), index$loss, index$factor) - dPVtranche <- BCtranche.pv(defaultprobplus, issuerweights, recov, cs, Kmod[1], Kmod[2], rho1, rho2, - Z, w, N)$bp - - BCtranche.pv(defaultprobminus, issuerweights, recov, cs, Kmod[1], Kmod[2], rho1, rho2, - Z, w, N)$bp + dPVtranche <- BCtranche.pv(indexplus, Kmod[1], Kmod[2], rho1, rho2, Z, w, N)$bp - + BCtranche.pv(indexminus, Kmod[1], Kmod[2], rho1, rho2, Z, w, N)$bp delta <- dPVtranche/(100*dPVindex) } ## dPVindex <- BCtranche.pv(portfolioplus, index, coupon, 0, 1, 0, 0.5, lu)$bp- -- cgit v1.2.3-70-g09d2