aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/calibrate_tranches_MF.R9
-rw-r--r--R/calibration.R3
2 files changed, 6 insertions, 6 deletions
diff --git a/R/calibrate_tranches_MF.R b/R/calibrate_tranches_MF.R
index 2361398f..5a6a97a8 100644
--- a/R/calibrate_tranches_MF.R
+++ b/R/calibrate_tranches_MF.R
@@ -19,6 +19,7 @@ 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"))
##figure out the tradedate
if(length(args) >= 1){
@@ -30,17 +31,15 @@ if(length(args) >= 1){
exportYC(tradedate)
## calibrate HY21
## calibrate the single names curves
-n.int <- 500
-list2env(GHquad(n.int), envir=parent.frame())
-Ngrid <- 201
-index <- load.index("hy21", date=tradedate, "5yr", Z, w, Ngrid)
+index <- creditIndex("hy21", "5yr")
+index <- set.index.desc(index, tradedate)
index <- set.singlenamesdata(index, tradedate)
## load tranche data
index <- set.tranchedata(index, tradedate)
##calibrate by modifying the factor distribution
index$w.mod <- build.MFdist(index)
dist <- MFlossdist(index)
-write.table(data.frame(Z=Z, w=index$w.mod),
+write.table(data.frame(Z=index$Z, w=index$w.mod),
file=file.path(root.dir, "Scenarios", "Calibration",
paste0("calibration-", tradedate, ".csv")),
col.names=T, row.names=F, sep=",")
diff --git a/R/calibration.R b/R/calibration.R
index 1f592889..fe531dcc 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -161,7 +161,8 @@ build.MFdist <- function(index, type="bottomup", tol=1e-2){
err <- 0
for(i in 1:n.credit){
for(j in 1:ncol(p)){
- err <- err + abs(crossprod(shockprob(p[i,j], rho[i], Z), program$weight) - index$defaultprob[i,j])
+ err <- err + abs(crossprod(shockprob(p[i,j], rho[i],
+ index$Z), program$weight) - index$defaultprob[i,j])
}
}