aboutsummaryrefslogtreecommitdiffstats
path: root/R/script_calibrate_tranches.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/script_calibrate_tranches.R')
-rw-r--r--R/script_calibrate_tranches.R17
1 files changed, 12 insertions, 5 deletions
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R
index 60578c95..8cd3182f 100644
--- a/R/script_calibrate_tranches.R
+++ b/R/script_calibrate_tranches.R
@@ -17,7 +17,14 @@ source(file.path(root.dir, "code", "R", "tranche_functions.R"))
source(file.path(root.dir, "code", "R", "yieldcurve.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
-MarkitData <- getMarkitIRData()
+#figure out the workdate
+filenames <- list.files(file.path(root.dir, "Scenarios", "Calibration"),
+ pattern = "hy19_singlenames*")
+dates <- sapply(filenames, function(x)x[3])
+workdate <- as.Date(sort(dates, decreasing = TRUE)[1])
+
+#retreive yield curve data
+MarkitData <- getMarkitIRData(workdate)
L1m <- buildMarkitYC(MarkitData, dt = 1/12)
L2m <- buildMarkitYC(MarkitData, dt = 1/6)
L3m <- buildMarkitYC(MarkitData)
@@ -27,7 +34,7 @@ setEvaluationDate(as.Date(MarkitData$effectiveasof))
## calibrate HY19
## calibrate the single names curves
singlenames.data <- read.csv(file.path(root.dir, "Scenarios", "Calibration",
- paste0("hy19_singlenames_", Sys.Date(), ".csv")))
+ paste0("hy19_singlenames_", workdate, ".csv")))
nondefaulted <- singlenames.data[!singlenames.data$ticker %in% hy19$defaulted,]
bps <- 1e-4
@@ -54,7 +61,7 @@ issuerweights <- rep(1/length(hy19portfolio), length(hy19portfolio))
K <- c(0, 0.15, 0.25, 0.35, 1)
Kmodified <- adjust.attachments(K, hy19$loss, hy19$factor)
markit.data <- read.csv(file.path(root.dir, "Scenarios", "Calibration",
- paste0("hy19_tranches_", Sys.Date(), ".csv")))
+ paste0("hy19_tranches_", workdate, ".csv")))
tranche.upf <- markit.data$Mid
tranche.running <- c(0.05, 0.05, 0.05, 0.05)
@@ -65,7 +72,7 @@ SurvProb <- SPmatrix(hy19portfolio.tweaked, hy19)
Ngrid <- 2 * nrow(nondefaulted) + 1
recov <- sapply(hy19portfolio.tweaked, attr, "recovery")
-cs <- couponSchedule(nextIMMDate(today()), hy19$maturity,"Q", "FIXED", 0.05, 0)
+cs <- couponSchedule(nextIMMDate(workdate), hy19$maturity,"Q", "FIXED", 0.05, 0)
##calibrate by modifying the factor distribution
bottomup <- 1:3
@@ -128,4 +135,4 @@ write.table(data.frame(Z=Z, w=w.mod),
paste0("calibration-", Sys.Date(), ".csv")),
col.names=T, row.names=F, sep=",")
save(singlenames.data, hy19, tranche.upf,
- file = file.path(root.dir, "Scenarios", "Calibration", paste0("marketdata-", Sys.Date(), ".RData")))
+ file = file.path(root.dir, "Scenarios", "Calibration", paste0("marketdata-", workdate, ".RData")))