diff options
Diffstat (limited to 'R/calibrate_tranches.R')
| -rw-r--r-- | R/calibrate_tranches.R | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/R/calibrate_tranches.R b/R/calibrate_tranches.R index 52802685..d1320883 100644 --- a/R/calibrate_tranches.R +++ b/R/calibrate_tranches.R @@ -1,22 +1,25 @@ library("parallel")
-root.dir <- "//WDSENTINEL/share/CorpCDOs/"
+if(.Platform$OS.type == "unix"){
+ root.dir <- "/home/share/CorpCDOs"
+}else{
+ root.dir <- "//WDSENTINEL/share/CorpCDOs"
+}
+
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"))
-cl <- makeCluster(6)
-
-MarkitData <- getMarkitIRData()
+tradedate <- Sys.Date()
+MarkitData <- getMarkitIRData(tradedate)
L1m <- buildMarkitYC(MarkitData, dt = 1/12)
L2m <- buildMarkitYC(MarkitData, dt = 1/6)
L3m <- buildMarkitYC(MarkitData)
L6m <- buildMarkitYC(MarkitData, dt = 1/2)
setEvaluationDate(as.Date(MarkitData$effectiveasof))
-## calibrate HY19
+## calibrate HY21
## calibrate the single names curves
singlenames.data <- read.table(file="clipboard", sep="\t", header=T)
nondefaulted <- singlenames.data[!singlenames.data$ticker %in% hy19$defaulted,]
@@ -24,10 +27,12 @@ bps <- 1e-4 cdsdates <- as.Date(character(0))
for(tenor in paste0(1:5, "y")){
- cdsdates <- c(cdsdates, cdsMaturity(tenor))
+ cdsdates <- c(cdsdates, cdsMaturity(tenor, date=tradedate))
}
-hy19portfolio <- c()
+hy21portfolio <- c()
+cs <- couponSchedule(IMMDate(tradedate), cdsdates[length(cdsdates)], "Q", "FIXED",
+ 1, tradedate, IMMDate(tradedate, "prev"))
for(i in 1:nrow(nondefaulted)){
SC <- new("creditcurve",
recovery=nondefaulted$recovery[i]/100,
@@ -36,10 +41,10 @@ for(i in 1:nrow(nondefaulted)){ quotes <- data.frame(maturity=cdsdates, upfront = as.numeric(nondefaulted[i,4:8])*0.01,
running=rep(nondefaulted$running[i]*bps, 5))
SC@curve <- cdshazardrate(quotes, nondefaulted$recovery[i]/100)
- hy19portfolio <- c(hy19portfolio, SC)
+ hy21portfolio <- c(hy21portfolio, SC)
}
-issuerweights <- rep(1/length(hy19portfolio), length(hy19portfolio))
+issuerweights <- rep(1/length(hy21portfolio), length(hh21portfolio))
hy19$indexref <- 1.0275
hy19portfolio.tweaked <- tweakcurves(hy19portfolio, hy19)
@@ -254,3 +259,14 @@ Rfun <- splinefun(c(0, cumsum(MFdist$R[,i])),c(0, seq(0, 1, length=Ngrid)), "mon r[i, j] <- Rfun(d1[j])
}
}
+
+issuerweights <- rep(1/100, 100)
+rho <- 0.45
+recov <- read.csv("~/code/python/recov.csv", header=F)
+recov <- as.numeric(recov$V1)
+survprob <- as.matrix(read.csv("~/code/python/survprob.csv", header=F))
+gq <- gauss.quad.prob(500, "normal")
+Z <- gq$nodes
+w <- gq$weights
+defaultprob <- 1-survprob
+test <- BClossdistC(defaultprob, issuerweights, recov, rho, Z, w, 101)
|
