aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/build_portfolios.R2
-rw-r--r--R/build_scenarios.R2
-rw-r--r--R/cds_utils.R7
-rw-r--r--R/index_definitions.R42
-rw-r--r--R/index_definitions.yml47
-rw-r--r--R/load_cf.R2
-rw-r--r--R/script_calibrate_tranches.R2
7 files changed, 58 insertions, 46 deletions
diff --git a/R/build_portfolios.R b/R/build_portfolios.R
index 34587f4d..3f062eb4 100644
--- a/R/build_portfolios.R
+++ b/R/build_portfolios.R
@@ -10,9 +10,9 @@ if(.Platform$OS.type == "unix"){
}
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
-source(file.path(root.dir, "code", "R", "index_definitions.R"))
source(file.path(root.dir, "code", "R", "cds_utils.R"))
source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
+hy21 <- load.index("hy21")
if(length(args) >=2){
argslist <- strsplit(args[-1], ",")
diff --git a/R/build_scenarios.R b/R/build_scenarios.R
index 48082cee..4735a4a8 100644
--- a/R/build_scenarios.R
+++ b/R/build_scenarios.R
@@ -34,10 +34,10 @@ if(length(args) >=2){
}
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
-source(file.path(root.dir, "code", "R", "index_definitions.R"))
source(file.path(root.dir, "code", "R", "etdb.R"))
source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
source(file.path(root.dir, "code", "R", "cds_utils.R"))
+load.index("hy21")
calibration.date <- addBusDay(tradedate, -1)
settledate <- addBusDay(tradedate, 3)
diff --git a/R/cds_utils.R b/R/cds_utils.R
index 2a93c52f..63487e22 100644
--- a/R/cds_utils.R
+++ b/R/cds_utils.R
@@ -165,3 +165,10 @@ yearFrac <- function(date1, date2, daycount="act/365") {
"act/365"=as.numeric( (as.Date(date2) - as.Date(date1)) / 365),
"act/360"=as.numeric( (as.Date(date2) - as.Date(date1)) / 360) )
}
+
+load.index <- function(index.name){
+ ## load index.name into the parent environment
+ indices <- yaml.load_file(file.path(root.dir, "code", "R", "index_definitions.yml"))
+ indices[[index.name]]$maturity <- as.Date(indices[[index.name]]$maturity, as.Date("1970-01-01"))
+ assign(index.name, indices[[index.name]], env = parent.env(environment()))
+}
diff --git a/R/index_definitions.R b/R/index_definitions.R
deleted file mode 100644
index 2ed8a505..00000000
--- a/R/index_definitions.R
+++ /dev/null
@@ -1,42 +0,0 @@
-hy21 <- list(maturity=as.Date("2018-12-20"),
- coupon=0.05,
- factor=1,
- loss=0,
- recovery=0.4)
-
-hy20 <- list(maturity=as.Date("2018-06-20"),
- coupon=0.05,
- factor=1,
- loss=0,
- recovery=0.4)
-
-hy19 <- list(maturity=as.Date("2017-12-20"),
- coupon=0.05,
- factor=1,
- loss=0,
- recovery=0.3)
-
-hy18 <- list(maturity=as.Date("2017-06-20"),
- coupon=0.05,
- factor=0.99,
- loss=0.0082375,
- recovery=0.3)
-
-hy17 <- list(maturity=as.Date("2016-12-20"),
- coupon=0.05,
- factor=0.96,
- loss=0.027075,
- recovery=0.3,
- defaulted=c("DYNHLD", "EK", "GM-ResCLLC", "PMI"))
-
-hy15 <- list(maturity=as.Date("2015-12-20"),
- coupon=0.05,
- factor=0.96,
- loss=0.026375,
- recovery=0.3)
-
-hy10 <- list(maturity=as.Date("2015-06-20"),
- coupon=0.05,
- factor=0.83,
- loss=0.1414,
- recovery=0.3)
diff --git a/R/index_definitions.yml b/R/index_definitions.yml
new file mode 100644
index 00000000..0274bdf2
--- /dev/null
+++ b/R/index_definitions.yml
@@ -0,0 +1,47 @@
+hy21:
+ maturity: 17885.0
+ coupon: 0.05
+ factor: 1.0
+ loss: 0.0e+00
+ recovery: 0.4
+hy20:
+ maturity: 17702.0
+ coupon: 0.05
+ factor: 1.0
+ loss: 0.0e+00
+ recovery: 0.4
+hy19:
+ maturity: 17520.0
+ coupon: 0.05
+ factor: 1.0
+ loss: 0.0e+00
+ recovery: 0.3
+hy18:
+ maturity: 17337.0
+ coupon: 0.05
+ factor: 0.99
+ loss: 0.0082375
+ recovery: 0.3
+hy17:
+ maturity: 17155.0
+ coupon: 0.05
+ factor: 0.96
+ loss: 0.027075
+ recovery: 0.3
+ defaulted:
+ - DYNHLD
+ - EK
+ - GM-ResCLLC
+ - PMI
+hy15:
+ maturity: 16789.0
+ coupon: 0.05
+ factor: 0.96
+ loss: 0.026375
+ recovery: 0.3
+hy10:
+ maturity: 16606.0
+ coupon: 0.05
+ factor: 0.83
+ loss: 0.1414
+ recovery: 0.3
diff --git a/R/load_cf.R b/R/load_cf.R
index b51d08d6..b61c21bd 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -24,7 +24,7 @@ source(file.path(root.dir, "code", "R", "cds_utils.R"))
source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
source(file.path(root.dir, "code", "R", "interpweights.R"))
-source(file.path(root.dir, "code", "R", "index_definitions.R"))
+load.index("hy21")
calibration.date <- addBusDay(tradedate, -1)
MarkitData <- getMarkitIRData(calibration.date)
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R
index 3f82052e..ab29feca 100644
--- a/R/script_calibrate_tranches.R
+++ b/R/script_calibrate_tranches.R
@@ -11,10 +11,10 @@ if(.Platform$OS.type == "unix"){
source(file.path(root.dir, "code", "R", "cds_utils.R"))
source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
-source(file.path(root.dir, "code", "R", "index_definitions.R"))
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"))
+load.index("hy21")
##figure out the tradedate
if(length(args) >= 1){