From 089f7bf1089b1825b94206b68d8138f4a529f30b Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 30 Jun 2014 17:51:44 -0400 Subject: add function to compute theta --- R/tranche_functions.R | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 469d68f..eb652b8 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -694,12 +694,22 @@ BCtranche.pv <- function(index, protection=FALSE){ theta.adjust.skew <- function(index, shortened=4){ #ajust the correlation skew by doing ATM mapping on the expected loss el <- EL(index) - elshort <- EL(index, shortened) + elshort <- EL(index, shortened=shortened) K <- index$K[-c(1,length(index$K))] rhofun <- splinefun(K, index$rho[-c(1, length(index$rho))], "natural") K <- el/elshort*K - return(c(0, rhofun(K))) - } + return(c(0, rhofun(K), NA)) +} + +BCtranche.theta <- function(index, shortened=4){ + temp <- BCtranche.pv(index) + index$rho <- theta.adjust.skew(index, shortened) + N <- nrow(index$cs)-shortened + index$cs <- index$cs[1:N,] + index$defaultprob <- index$defaultprob[,1:N] + temp2 <- BCtranche.pv(index) + return(temp2$bp-temp$bp+index$tranche.running) +} BCtranche.delta <- function(index, tradedate = Sys.Date()){ ## computes the tranche delta (on current notional) by doing a proportional -- cgit v1.2.3-70-g09d2