diff options
Diffstat (limited to 'R/build_scenarios.R')
| -rw-r--r-- | R/build_scenarios.R | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index 46d4ae3a..076672d1 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -5,10 +5,20 @@ if(.Platform$OS.type == "unix"){ }
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"))
-workdate <- as.Date('2013-01-24')
-calibration.date <- as.Date('2013-01-24')
+prevBusDay <- function(){
+ i <- 1
+ while(!isBusinessDay(calendar = "UnitedStates/GovernmentBond", Sys.Date() - i)){
+ i <- i+1
+ }
+ return( Sys.Date() - i )
+}
+
+workdate <- Sys.Date()
+calibration.date <- prevBusDay()
calibration <- read.table(file.path(root.dir, "Scenarios", "Calibration",
paste0("calibration-", calibration.date,".csv")), sep=",", header=T)
@@ -17,13 +27,13 @@ w <- calibration$w rho <- 0.45
Ngrid <- 201
-dealnames <- list.files(file.path(root.dir, "Scenarios", paste0("Portfolios_", calibration.date)),
- pattern="*.RData")
-dealnames <- sapply(strsplit(dealnames, "\\."), function(x)x[1])
+## dealnames <- list.files(file.path(root.dir, "Scenarios", paste0("Portfolios_", calibration.date)),
+## pattern="*.RData")
+## dealnames <- sapply(strsplit(dealnames, "\\."), function(x)x[1])
support <- seq(0, 1, length = Ngrid)
for(deal.name in dealnames){
- load(file.path(root.dir, "Scenarios", paste("Portfolios", calibration.date, sep="_"),
+ load(file.path(root.dir, "Scenarios", paste("Portfolios", workdate, sep="_"),
paste(deal.name, "RData", sep=".")))
dp <- A$DP
@@ -32,7 +42,7 @@ for(deal.name in dealnames){ ppmod <- MFupdate.probC(-Z, w, rho, pp)
dist.joint <- MFlossdist.prepay.joint2(w, Z, rho, dp, dpmod, pp, ppmod,
deal.weights, 1-S, Ngrid)
-
+
distDR <- dist.transform(dist.joint)
## compute E(R|D)
@@ -91,7 +101,7 @@ for(deal.name in dealnames){ recoverymonthly[i,] <- approx(deal.dates, intexrecov[i,], deal.datesmonthly, rule=2)$y
}
- save.dir <- file.path(root.dir, "Scenarios", paste("Intex curves", calibration.date, sep="_"), "csv")
+ save.dir <- file.path(root.dir, "Scenarios", paste("Intex curves", workdate, sep="_"), "csv")
if(!file.exists(save.dir)){
dir.create(save.dir, recursive = T)
}
|
