aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/test_options.R18
1 files changed, 9 insertions, 9 deletions
diff --git a/R/test_options.R b/R/test_options.R
index ef90c1f0..babc8bf4 100644
--- a/R/test_options.R
+++ b/R/test_options.R
@@ -7,12 +7,13 @@ 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")
+tradedate <- as.Date("2016-08-02")
exportYC(tradedate)
-index <- creditIndex("hy24", "5yr")
+index <- creditIndex("ig26", "5yr")
index <- set.index.desc(index, tradedate)
index <- set.singlenamesdata(index, tradedate)
-
+index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity,"Q", "FIXED", 1,
+ 0, tradedate, IMMDate(tradedate, "prev"))
tweakindex <- function(index, refprice){
fixedRate <- couponfromindex(index$name, index$tenor)*1e-4
index$quotes <- data.frame(maturity=index$maturity, refspread=fixedRate, refprice=refprice)
@@ -28,22 +29,21 @@ tweakindex <- function(index, refprice){
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"))
+exerciseDates <- c(as.Date("2016-08-17"), as.Date("2016-09-21"), as.Date("2016-10-19"))
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))
+ fp2 <- c(fp2, forwardflatcds(h, index$cs, tradedate, exerciseDates[i], fixedRate=0.01, R=0.4))
}
calib <- function(S0, index, fp, exerciseDate, sigma, quad){
T <- yearFrac(index$tradedate, exerciseDate)
S <- S0 * exp(-sigma^2/2*T+sigma*quad$Z*sqrt(T))
- guess <- crossprod(quad$w, unlist(lapply(S, function(S){
- snacpv(index$cs, S, index$quotes$refspread, index$recovery, exerciseDate)})))
+ values <- unlist(lapply(S, function(s){
+ snacpv(index$cs, s, index$quotes$refspread, index$recovery, exerciseDate)}))
+ guess <- crossprod(quad$w, values)
return( guess - fp )
}