diff options
| -rw-r--r-- | R/build_scenarios.R | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index 076672d1..c877be0b 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -1,25 +1,38 @@ +args <- commandArgs(trailingOnly=TRUE)
+
if(.Platform$OS.type == "unix"){
root.dir <- "/home/share/CorpCDOs"
}else{
root.dir <- "//WDSENTINEL/share/CorpCDOs"
}
+if(len(args) >= 1){
+ workdate <- args[1]
+}else{
+ workdate <- Sys.Date()
+}
+
+if(len(args) >=2){
+ dealnames <- args[2:len(args)]
+}else{
+ dealnames <- read.table(file.path(root.dir, "scripts", "scenarios.txt"))$V1
+ unlink(file.path(root.dir, "scripts", "scenarios.txt"))
+}
+print(dealnames)
+
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
-dealnames <- read.table(file.path(root.dir, "scripts", "scenarios.txt"))$V1
-unlink(file.path(root.dir, "scripts", "scenarios.txt"))
source(file.path(root.dir, "code", "R", "index_definitions.R"))
-prevBusDay <- function(){
+prevBusDay <- function(workdate = Sys.Date()){
i <- 1
- while(!isBusinessDay(calendar = "UnitedStates/GovernmentBond", Sys.Date() - i)){
+ while(!isBusinessDay(calendar = "UnitedStates/GovernmentBond",
+ workdate - i)){
i <- i+1
}
- return( Sys.Date() - i )
+ return( workdate - i )
}
-workdate <- Sys.Date()
-calibration.date <- prevBusDay()
-
+calibration.date <- prevBusDay(workdate)
calibration <- read.table(file.path(root.dir, "Scenarios", "Calibration",
paste0("calibration-", calibration.date,".csv")), sep=",", header=T)
Z <- calibration$Z
@@ -115,6 +128,6 @@ for(deal.name in dealnames){ write.table(rbind(100*reinvloanprice, 100*reinvbondprice),
file = file.path(save.dir, paste0(deal.name,"-reinvprices.csv")),
row.names=F, col.names=F, sep=",")
- save(scenariosd, scenariosr, file=file.path(save.dir, paste0(deal.name, ".RData")))
+ save(scenariosd, scenariosr, distDR, file=file.path(save.dir, paste0(deal.name, ".RData")))
cat("generated scenarios for:", deal.name, "\n")
}
|
