diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/build_scenarios.R | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index a4b952e2..5c9b6033 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -201,24 +201,23 @@ for(j in seq_along(dealnames)){ }
recoverymonthly <- pmin(recoverymonthly,1)
## compute reinvestment price
- if(reinvflags[j]){
- if(deal.data$"Reinv End Date" <= workdate){
+ if(!is.na(deal.data$"Reinv End Date") && deal.data$"Reinv End Date" <= workdate){
## we cap rolling maturity at the current weighted average maturity of the portfolio
rollingmaturity <- (crossprod(sapply(deal.portfolio$SC, creditcurve.maturity),
deal.portfolio$notional)/sum(deal.portfolio$notional)
- as.numeric(workdate))/365*12
- }else{
+ }else{
rollingmaturity <- basecase.rollingmaturity
- }
- DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthlylagged))
- df <- DC$discounts
- forwards <- DC$forwards
- #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)){
+ }
+ DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthlylagged))
+ df <- DC$discounts
+ forwards <- DC$forwards
+ ##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),
@@ -227,7 +226,7 @@ for(j in seq_along(dealnames)){ forwardportfolioprice(deal.portfolio, deal.datesmonthly[i],
min(deal.datesmonthly[i]+rollingmaturity*30, deal.data$maturity),
"fixed", reinvfixed, 0.4))
- }
+ }
## reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, reinvspread,
## reinvfixed, rollingmaturity, reinvlag)
@@ -266,7 +265,6 @@ for(j in seq_along(dealnames)){ ## maturingbalance[,min(t+rollingmaturity, length(deal.datesmonthly))] +
## reinvdollar[,t]/loanprices[t]
## }
- }
save.dir <- file.path(root.dir, "Scenarios", paste("Intex curves", workdate, sep="_"), "csv")
if(!file.exists(save.dir)){
@@ -279,18 +277,27 @@ for(j in seq_along(dealnames)){ write.table(100 * recoverymonthly,
file=file.path(save.dir, paste0(dealnames[j],"-recovery.csv")),
row.names=F, col.names=F, sep=",", na="NaN")
+ ## write.table(100 * reinvprices$loan,
+ ## file = file.path(save.dir, paste0(dealnames[j], "-floatreinvprices.csv")),
+ ## row.names=F, col.names=F, sep=",")
+ ## 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=",")
+ configfile <- file.path(save.dir, paste0(dealnames[j], ".config"))
+ cat("[config]\n", file = configfile)
+ cat(paste("rollingmat", as.integer(rollingmaturity), sep="="), "\n",
+ append=TRUE, file = configfile)
if(reinvflags[j]){
- ## write.table(100 * reinvprices$loan,
- ## file = file.path(save.dir, paste0(dealnames[j], "-floatreinvprices.csv")),
- ## row.names=F, col.names=F, sep=",")
- ## 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=",")
- cat(as.integer(rollingmaturity), file=file.path(save.dir, paste0(dealnames[j], "-rollingmat")))
+ cat(paste("reinvflag", "True", sep="="), "\n", append= TRUE,
+ file = configfile)
+ }else{
+ cat(paste("reinvflag", "False", sep="="), "\n", append= TRUE,
+ file = configfile)
}
+
save(scenariosd, scenariosr, dist.joint, file=file.path(save.dir, paste0(dealnames[j], ".RData")),
compress="xz")
|
