aboutsummaryrefslogtreecommitdiffstats
path: root/R/tranche_functions.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/tranche_functions.R')
-rw-r--r--R/tranche_functions.R25
1 files changed, 19 insertions, 6 deletions
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index 46c15bbd..125b5a40 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -349,19 +349,32 @@ EL <- function(index, discounted=TRUE, shortened=0){
## should be very close to the protection leg of the portfolio of cds
## index should be a list with issuerweights, recov, defaultprob and cs parameters
## shortened: number of quarters to shorten the maturity by
- Ncol <- ncol(index$defaultprob)-shortened
- ELvec <- as.numeric(crossprod(index$issuerweights * (1-index$recov), index$defaultprob[,1:Ncol]))
+ Ncol <- ncol(index$defaultprob)
+ if(is.null(Ncol) && shortened==0){
+ DP <- index$defaultprob
+ df <- index$cs$df
+ }else{
+ DP <- index$defaultprob[,1:(Ncol-shortened)]
+ df <- index$cs$df[1:(Ncol-shortened)]
+ }
+ ELvec <- as.numeric(crossprod(index$issuerweights * (1-index$recov), DP))
if(!discounted){
return( ELvec[length(ELvec)] )
}else{
- return( sum(index$cs$df[1:Ncol]*diff(c(0, ELvec))) )
+ return( sum(df*diff(c(0, ELvec))) )
}
}
BCindex.pv <- function(index, discounted=TRUE, shortened=0){
- Ncol <- ncol(index$defaultprob)-shortened
- ELvec <- as.numeric(crossprod(index$issuerweights * (1-index$recov), index$defaultprob[,1:Ncol]))
- size <- 1-as.numeric(crossprod(index$issuerweights, index$defaultprob[,1:Ncol]))
+ Ncol <- ncol(index$defaultprob)
+ if(is.null(Ncol) && shortened==0){
+ DP <- index$defaultprob
+ Ncol <- 1
+ }else{
+ DP <- index$defaultprob[,1:(Ncol-shortened)]
+ }
+ ELvec <- as.numeric(crossprod(index$issuerweights * (1-index$recov), DP))
+ size <- 1-as.numeric(crossprod(index$issuerweights, DP))
sizeadj <- 0.5*(c(1, size[-length(size)])+size)
if(!discounted){
pl <- -ELvec[length(ELvec)]