aboutsummaryrefslogtreecommitdiffstats
path: root/R/test_options.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/test_options.R')
-rw-r--r--R/test_options.R40
1 files changed, 40 insertions, 0 deletions
diff --git a/R/test_options.R b/R/test_options.R
new file mode 100644
index 00000000..5b8ab782
--- /dev/null
+++ b/R/test_options.R
@@ -0,0 +1,40 @@
+root.dir <- "/home/share/CorpCDOs"
+code.dir <- if(Sys.getenv("CODE_DIR")!="") Sys.getenv("CODE_DIR") else root.dir
+source(file.path(code.dir, "code", "R", "yieldcurve.R"))
+source(file.path(code.dir, "code", "R", "optimization.R"))
+source(file.path(code.dir, "code", "R", "calibration.R"), chdir=TRUE)
+source(file.path(code.dir, "code", "R", "serenitasdb.R"))
+source(file.path(code.dir, "code", "R", "creditIndex.R"))
+source(file.path(code.dir, "code", "R", "tranche_functions.R"))
+
+tradedate <- as.Date("2015-05-28")
+exportYC(tradedate)
+index <- creditIndex("hy24", "5yr")
+index <- set.index.desc(index, tradedate)
+index <- set.singlenamesdata(index, tradedate)
+
+tweakindex <- function(index, refprice){
+ fixedRate <- couponfromindex(index$name, index$tenor)*1e-4
+ index$quotes <- data.frame(maturity=index$maturity, refspread=fixedRate, refprice=refprice)
+ index$quotes$spread <- fixedRate
+ index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity,"Q", "FIXED", 1,
+ 0, tradedate, IMMDate(tradedate, "prev"))
+ index$quotes$price <- index$quotes$refprice/100
+ tweak <- tweakcurves(index, index$tradedate)
+ index$portfolio <- NULL
+ index <- c(index, tweak)
+ return( index )
+}
+ref <- 107
+newindex <- tweakindex(index, ref)
+h <- cdshazardrate.flat(1-ref/100, 0.05, index$maturity, 0.3, tradedate)
+exerciseDates <- c(as.Date("2015-06-17"), as.Date("2015-07-15"), as.Date("2015-08-19"),
+ as.Date("2015-09-16"), as.Date("2015-10-21"),
+ as.Date("2015-11-18"), as.Date("2015-12-16"), as.Date("2016-01-20"))
+
+fp <- c()
+fp2 <- c()
+for(i in seq_along(exerciseDates)){
+ fp <- c(fp, defaultAdjustedForwardIndexPrice(newindex, exerciseDates[i]))
+ fp2 <- c(fp2, forwardflatcds(h, index$cs, tradedate, exerciseDates[i], fixedRate=0.05, R=0.3))
+}