diff options
Diffstat (limited to 'R/load_cf.R')
| -rw-r--r-- | R/load_cf.R | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/R/load_cf.R b/R/load_cf.R index 723a53aa..9fe4f207 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -34,13 +34,6 @@ tranches <- c("COLLAT_REINVEST", "COLLAT_INITIAL") n.scenarios <- 100
flag <- FALSE
-dealnames <- c("ares11", "cifc071", "cifc122", "comst", "duanst1", "empf2",
- "galax8", "gulf052", "halcli1", "hals071", "hewett3", "hewett6",
- "hillmf", "ingim2", "ingim3", "katon10", "katonah8", "katonah9",
- "landmrk6", "landmrk8", "latcl3", "madpk6", "mayp", "mtwil2",
- "oakcp3", "oceant1", "pacific3", "primus2", "sappv1", "saratg_1",
- "shack1", "standay", "sumlk", "t2if1", "vent12", "vent7", "vent9",
- "wthrs3")
allfiles <- list.files(file.path(root.dir, "Scenarios", paste0("Prices_", workdate)), "*.txt")
allfiles <- unique(sapply(strsplit(allfiles, "-"), function(x) x[1]))
allfiles <- allfiles[!(allfiles=="Total")]
@@ -63,8 +56,15 @@ for(dealname in dealnames){ for(tranche in tranches){
for(i in 1:n.scenarios){
filename <- paste0(paste(toupper(dealname), tranche, "CF", paste0("Scen", i), sep="-"), ".txt")
- data <- read.table(file.path(root.dir, "Scenarios", paste0("Prices_", workdate), filename),
- sep="\t", header=F, skip=3, colClasses="character", comment.char="")
+ ## we catch the error if there is an error reading the file
+ ## happen if the tranche is missing in intex
+ data <- tryCatch(read.table(file.path(root.dir, "Scenarios", paste0("Prices_", workdate), filename),
+ sep="\t", header=F, skip=3, colClasses="character", comment.char=""),
+ error = function(e) e)
+ if(inherits(data, "error")){
+ cfdata[[dealname]] <- NULL
+ break
+ }
data <- data[,1:4]
colnames(data) <- c("Date", "Cashflow", "Principal", "Interest")
data$Date <- as.Date(data$Date, "%b %d, %Y")
@@ -106,7 +106,7 @@ for(dealname in dealnames){ }
r <- c()
-for(dealname in dealnames){
+for(dealname in names(cfdata)){
r <- rbind(r, c(cfdata[[dealname]]$mv, cfdata[[dealname]]$currbal, apply(cfdata[[dealname]]$COLLAT_REINVEST, 2, mean)[1], apply(cfdata[[dealname]]$COLLAT_INITIAL, 2, mean)[1]))
}
colnames(r) <- c("mv", "currbal", "Reinvest", "Initial")
|
