aboutsummaryrefslogtreecommitdiffstats
path: root/R/build_scenarios.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/build_scenarios.R')
-rw-r--r--R/build_scenarios.R36
1 files changed, 22 insertions, 14 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R
index 4f0ebee5..bcd561f4 100644
--- a/R/build_scenarios.R
+++ b/R/build_scenarios.R
@@ -13,10 +13,12 @@ if(length(args) >= 1){
}
if(length(args) >=2){
- dealnames <- args[2:length(args)]
+ dealnames <- args[2:length(args)]
}else{
- dealnames <- read.table(file.path(root.dir, "scripts", "scenarios.txt"))$V1
- unlink(file.path(root.dir, "scripts", "scenarios.txt"))
+ data <- read.table(file.path(root.dir, "scripts", "scenarios.txt"))
+ dealnames <- data$V1
+ reinvflags <- data$V2
+ unlink(file.path(root.dir, "scripts", "scenarios.txt"))
}
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
@@ -93,6 +95,7 @@ setEvaluationDate(as.Date(MarkitData$effectiveasof))
support <- seq(0, 1, length = Ngrid)
## 3 months
recoverylag <- 90
+j <- 1
for(deal.name in dealnames){
load(file.path(root.dir, "Scenarios", paste("Portfolios", workdate, sep="_"),
paste(deal.name, "RData", sep=".")))
@@ -165,11 +168,12 @@ for(deal.name in dealnames){
}
## compute reinvestment price
- DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthlylagged))
- df <- DC$discounts
- forwards <- DC$forwards
- reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, 0.025, 0.07, 84, 3)
-
+ if(reinvflags[j]){
+ DC <- DiscountCurve(L3m$params, L3m$tsQuotes, yearFrac(L3m$params$tradeDate, deal.datesmonthlylagged))
+ df <- DC$discounts
+ forwards <- DC$forwards
+ reinvprices <- compute.reinvprices(df, forwards, cdrmonthly, recoverymonthly, 0.025, 0.07, 84, 3)
+ }
## prev <- scenariosrmonthly[,1]
## loanprices <- c()
## bondprices <- c()
@@ -192,13 +196,17 @@ for(deal.name in dealnames){
write.table(100 * recoverymonthly,
file=file.path(save.dir, paste0(deal.name,"-recovery.csv")),
row.names=F, col.names=F, sep=",")
- write.table(100 * reinvprices$loan,
- file = file.path(save.dir, paste0(deal.name, "-floatreinvprices.csv")),
- row.names=F, col.names=F, sep=",")
- write.table(100 * reinvprices$bond,
- file = file.path(save.dir, paste0(deal.name, "-fixedreinvprices.csv")),
- row.names=F, col.names=F, sep=",")
+ if(reinvflags[j]){
+ write.table(100 * reinvprices$loan,
+ file = file.path(save.dir, paste0(deal.name, "-floatreinvprices.csv")),
+ row.names=F, col.names=F, sep=",")
+ write.table(100 * reinvprices$bond,
+ file = file.path(save.dir, paste0(deal.name, "-fixedreinvprices.csv")),
+ row.names=F, col.names=F, sep=",")
+ }
save(scenariosd, scenariosr, dist.joint, file=file.path(save.dir, paste0(deal.name, ".RData")),
compress="xz")
+
cat("generated scenarios for:", deal.name, "\n")
+ j <- j+1
}