From f01964c779bfe3631bb608b7865ba7608b0ccef2 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 14 Jul 2014 15:41:16 -0400 Subject: simplify code, and small speed up --- R/tranche_functions.R | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'R') diff --git a/R/tranche_functions.R b/R/tranche_functions.R index eb652b8..16960e0 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -729,24 +729,18 @@ BCtranche.delta <- function(index, tradedate = Sys.Date()){ return(newindex) } }) - dPVindex <- indexpv(index.list[[2]], tradedate = tradedate, clean = FALSE)$bp - - indexpv(index.list[[3]], tradedate = tradedate, clean = FALSE)$bp - dPVindex2 <- indexpv(index.list[[4]], tradedate = tradedate, clean = FALSE)$bp - - indexpv(index, tradedate = tradedate, clean = FALSE)$bp - dPVindex1 <- indexpv(index.list[[2]], tradedate = tradedate, clean = FALSE)$bp- - indexpv(index, tradedate = tradedate, clean = FALSE)$bp - - bp <- matrix(0, length(index$K)-1, 4) + + bp <- matrix(0, length(index$K)-1, length(index.list)) + indexbp <- rep(0, length(index.list)) for(j in seq_along(index.list)){ temp <- BCtranche.pv(index.list[[j]]) + indexbp[j] <- indexpv(index.list[[j]], tradedate = tradedate, clean = FALSE)$bp bp[,j] <- temp$bp } - dPVtranche <- bp[,2]-bp[,3] - dPVtranche2 <- bp[,4] - bp[,1] - deltas <- dPVtranche/dPVindex - deltasplus <- dPVtranche2/dPVindex2 - gammas <- (deltasplus-deltas)/dPVindex1/100 + deltas <- (bp[,2]-bp[,3])/(indexbp[2]-indexbp[3]) + deltasplus <- (bp[,4]-bp[,1])/(indexbp[4]-indexbp[1]) + gammas <- (deltasplus-deltas)/(indexbp[1]-indexbp[1])/100 return( list(deltas=deltas, gammas=gammas) ) } -- cgit v1.2.3-70-g09d2