aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/cds_functions_generic.R8
-rw-r--r--R/script_calibrate_tranches.R6
2 files changed, 7 insertions, 7 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index 7ce84daa..a38e38ef 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -538,9 +538,9 @@ tweakportfolio <- function(portfolio, epsilon, multiplicative=TRUE){
return( r )
}
-indexpv <- function(portfolio, index, epsilon=0){
+indexpv <- function(portfolio, index, epsilon=0, workdate=Sys.Date()){
## computes the intrinsic index pv of a portfolio of cds
- cs <- couponSchedule(nextIMMDate(Sys.Date()), index$maturity, "Q", "FIXED", index$coupon)
+ cs <- couponSchedule(nextIMMDate(workdate+1), index$maturity, "Q", "FIXED", index$coupon)
if(epsilon!=0){
portfolio <- tweakportfolio(portfolio, epsilon)
}
@@ -598,11 +598,11 @@ portfolioduration <- function(portfolio, maturity){
return( crossprod(durations, portfolio$notional)/sum(portfolio$notional) )
}
-tweakcurves <- function(portfolio, index){
+tweakcurves <- function(portfolio, index, workdate=Sys.Date()){
## computes the tweaking factor
epsilon <- 0
f <- function(epsilon, ...){
- abs(indexpv(portfolio, index, epsilon)$bp-index$indexref)
+ abs(indexpv(portfolio, index, epsilon, workdate)$bp-index$indexref)
}
epsilon <- optimize(f, c(-0.5, 0.5), portfolio, index, tol=1e-6)$minimum
cat("tweak = ", epsilon, "\n")
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R
index 2f740248..5dfe59e0 100644
--- a/R/script_calibrate_tranches.R
+++ b/R/script_calibrate_tranches.R
@@ -43,7 +43,7 @@ bps <- 1e-4
cdsdates <- as.Date(character(0))
for(tenor in paste0(1:5, "y")){
- cdsdates <- c(cdsdates, cdsMaturity(tenor, date=workdate))
+ cdsdates <- c(cdsdates, cdsMaturity(tenor, date=workdate+1))
}
hy21portfolio <- c()
@@ -70,7 +70,7 @@ tranche.upf <- markit.data$Mid
tranche.running <- c(0.05, 0.05, 0.05, 0.05)
# get the index ref
hy21$indexref <- markit.data$bidRefPrice[1]/100
-hy21portfolio.tweaked <- tweakcurves(hy21portfolio, hy21)
+hy21portfolio.tweaked <- tweakcurves(hy21portfolio, hy21, workdate)
SurvProb <- SPmatrix(hy21portfolio.tweaked, hy21)
Ngrid <- 2 * nrow(nondefaulted) + 1
@@ -92,7 +92,7 @@ p <- defaultprob
rho <- rep(0.45, n.credit)
result <- matrix(0, 4, n.int)
-for(l in 1:100){
+for(l in 1:150){
Rstoch <- array(0, dim=c(n.credit, n.int, ncol(SurvProb)))
for(t in 1:ncol(SurvProb)){
for(i in 1:n.credit){