diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/load_cf.R | 16 | ||||
| -rw-r--r-- | R/tranche_functions.R | 9 |
2 files changed, 17 insertions, 8 deletions
diff --git a/R/load_cf.R b/R/load_cf.R index c97247cc..73601c7b 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -123,10 +123,18 @@ getdealcf <- function(dealnames, zipfiles, tradedate=Sys.Date()){ break
flag <- FALSE
}
- data <- data[-c(1,2),][,`:=`(Date=as.Date(Date, "%b %d, %Y"),
- Cashflow = sanitize.column(Cashflow),
- Principal = sanitize.column(Principal),
- Interest = sanitize.column(Interest))]
+ data <- tryCatch({
+ data[-c(1,2),][,`:=`(Date=as.Date(Date, "%b %d, %Y"),
+ Cashflow = sanitize.column(Cashflow),
+ Principal = sanitize.column(Principal),
+ Interest = sanitize.column(Interest))]
+ },warning=function(w){
+ message("handling warning: ", conditionMessage(w))
+ NULL})
+ if(is.null(data)){
+ break
+ flag <- FALSE
+ }
setkey(data, "Date")
r[i,] <- as.numeric(df[data, roll=TRUE][,list(sum(Cashflow*Discounts),
sum(Principal*Discounts),
diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 7679b076..b6628ac4 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -325,7 +325,7 @@ MFtranche.delta <- function(index){ BCtranche.corr01 <- function(index, eps=0.01, complement=FALSE){ ##does a parallel shift of the skew and computes the change in pv before <- BCtranche.pv(index, complement=complement) - index$rho[-1] <- exp(log(index$rho[-1])*(1+eps)) + index$rho[-1] <- index$rho[-1])*(1+eps) after <- BCtranche.pv(index, complement=complement) return(after$bp-before$bp) } @@ -333,13 +333,14 @@ BCtranche.corr01 <- function(index, eps=0.01, complement=FALSE){ BCtranche.VaR <- function(index, skew.shocks, complement=FALSE){ before <- BCtranche.pv(index, complement=complement) n <- length(index$rho) - r <- matrix(0, nrow(skew.shocks)) - logskew <- log(index$skew[-c(1,n)]) + r <- matrix(0, nrow(skew.shocks), n-1) + logskew <- log(index$rho[-c(1,n)]) for(i in 1:nrow(skew.shocks)){ index$rho[-c(1,n)] <- exp(logskew*(1+skew.shocks[i,])) after <- BCtranche.pv(index, complement=complement) - r[i,] <- before-after + r[i,] <- before$bp-after$bp } + return( r ) } EL <- function(index, discounted=TRUE, shortened=0){ |
