diff options
| -rw-r--r-- | R/build_scenarios.R | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index e3fd1ec3..6bf06a9f 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -35,7 +35,7 @@ get.reinvassets <- function(dealname, workdate){ dealname, workdate)
data <- dbGetQuery(dbCon, sqlstr)
for(i in 1:dim(data)[1]){
- r[[data$issuername[i]]] <- data$fixedorfloat[i]
+ r[[data$issuername[i]]] <- list(coupontype=data$fixedorfloat[i], liborfloor=data$liborfloor[i])
}
return( r )
}
@@ -209,17 +209,25 @@ for(j in seq_along(dealnames)){ ##we need to jack up the reinvestment prices somehow so let's add a 75bps tweak...
## reinvprices.tweak <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread+0.0075,
## reinvfixed+0.0075, rollingmaturity, reinvlag)
- loanprices <- c()
- bondprices <- c()
- for(i in seq_along(deal.datesmonthly)){
- loanprices <- c(loanprices,
- forwardportfolioprice(deal.portfolio, deal.datesmonthly[i],
- min(deal.datesmonthly[i]+rollingmaturity*30, deal.data$maturity),
- "float", reinvspread, 0.7))
- bondprices <- c(bondprices,
- forwardportfolioprice(deal.portfolio, deal.datesmonthly[i],
- min(deal.datesmonthly[i]+rollingmaturity*30, deal.data$maturity),
- "fixed", reinvfixed, 0.4))
+
+ reinvassets <- get.reinvassets(dealnames[j], workdate)
+ reinvprices <- list()
+ for(n.asset in seq_along(reinvassets)){
+ asset <- reinvassets[[n.asset]]
+ reinvprices[[names(reinvassets)[n.asset]]] <- numeric(length(deal.datesmonthly))
+ if(asset$coupontype=="FLOAT") {
+ coupon <- reinvspread
+ R <- 0.7
+ }else{
+ coupon <- reinvfixed
+ R <- 0.3
+ }
+ for(i in seq_along(deal.datesmonthly)){
+ reinvprices[[names(reinvassets)[n.asset]]][i] <-
+ 100 * forwardportfolioprice(deal.portfolio, deal.datesmonthly[i],
+ min(deal.datesmonthly[i]+rollingmaturity*30, deal.data$maturity),
+ asset$coupontype, coupon, R, asset$liborfloor/100)
+ }
}
## reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread,
## reinvfixed, rollingmaturity, reinvlag)
@@ -277,9 +285,8 @@ for(j in seq_along(dealnames)){ ## write.table(100 * reinvprices$bond,
## file = file.path(save.dir, paste0(dealnames[j], "-fixedreinvprices.csv")),
## row.names=F, col.names=F, sep=",")
- write.table(cbind(100 * loanprices, 100 * bondprices),
- file = file.path(save.dir, paste0(dealnames[j], "-reinvprices.csv")),
- row.names=F, col.names=F, sep=",")
+ write.table(reinvprices, file = file.path(save.dir, paste0(dealnames[j], "-reinvprices.csv")),
+ row.names=F, col.names=T, sep=",")
configfile <- file.path(save.dir, paste0(dealnames[j], ".config"))
cat("[config]\n", file = configfile)
cat(paste("rollingmat", as.integer(rollingmaturity), sep="="), "\n",
|
