diff options
Diffstat (limited to 'R/script_calibrate_tranches.R')
| -rw-r--r-- | R/script_calibrate_tranches.R | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R index 5dfe59e0..3f82052e 100644 --- a/R/script_calibrate_tranches.R +++ b/R/script_calibrate_tranches.R @@ -16,17 +16,17 @@ 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"))
-##figure out the workdate
+##figure out the tradedate
if(length(args) >= 1){
- workdate <- as.Date(args[1])
+ tradedate <- as.Date(args[1])
}else{
- workdate <- Sys.Date()
+ tradedate <- Sys.Date()
}
futurequotes <- read.csv(file.path(root.dir, "data", "Yield Curves",
- sprintf("futures-%s.csv", workdate)), header=F)
+ sprintf("futures-%s.csv", tradedate)), header=F)
#retrieve yield curve data
-MarkitData <- getMarkitIRData(workdate)
+MarkitData <- getMarkitIRData(tradedate)
L1m <- buildMarkitYC(MarkitData, futurequotes[,2], dt = 1/12)
L2m <- buildMarkitYC(MarkitData, futurequotes[,2], dt = 1/6)
L3m <- buildMarkitYC(MarkitData, futurequotes[,2])
@@ -37,24 +37,24 @@ setCalendarContext("UnitedStates/GovernmentBond") ## calibrate HY21
## calibrate the single names curves
singlenames.data <- read.csv(file.path(root.dir, "Scenarios", "Calibration",
- paste0("hy21_singlenames_", workdate, ".csv")))
+ paste0("hy21_singlenames_", tradedate, ".csv")))
nondefaulted <- singlenames.data[!singlenames.data$ticker %in% hy21$defaulted,]
bps <- 1e-4
cdsdates <- as.Date(character(0))
for(tenor in paste0(1:5, "y")){
- cdsdates <- c(cdsdates, cdsMaturity(tenor, date=workdate+1))
+ cdsdates <- c(cdsdates, cdsMaturity(tenor, date=tradedate+1))
}
hy21portfolio <- c()
for(i in 1:nrow(nondefaulted)){
SC <- new("creditcurve",
recovery=nondefaulted$recovery[i]/100,
- startdate=workdate,
+ startdate=tradedate,
issuer=as.character(nondefaulted$ticker[i]))
quotes <- data.frame(maturity=cdsdates, upfront = as.numeric(nondefaulted[i,4:8]) /100,
running=rep(nondefaulted$running[i] * bps, 5))
- SC@curve <- cdshazardrate(quotes, nondefaulted$recovery[i]/100, workdate)
+ SC@curve <- cdshazardrate(quotes, nondefaulted$recovery[i]/100, tradedate)
hy21portfolio <- c(hy21portfolio, SC)
}
@@ -64,18 +64,18 @@ issuerweights <- rep(1/length(hy21portfolio), length(hy21portfolio)) K <- c(0, 0.15, 0.25, 0.35, 1)
Kmodified <- adjust.attachments(K, hy21$loss, hy21$factor)
markit.data <- read.csv(file.path(root.dir, "Scenarios", "Calibration",
- paste0("hy21_tranches_", workdate, ".csv")))
+ paste0("hy21_tranches_", tradedate, ".csv")))
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, workdate)
+hy21portfolio.tweaked <- tweakcurves(hy21portfolio, hy21, tradedate)
SurvProb <- SPmatrix(hy21portfolio.tweaked, hy21)
Ngrid <- 2 * nrow(nondefaulted) + 1
recov <- sapply(hy21portfolio.tweaked, attr, "recovery")
-cs <- couponSchedule(nextIMMDate(workdate), hy21$maturity,"Q", "FIXED", 0.05, 0)
+cs <- couponSchedule(nextIMMDate(tradedate), hy21$maturity,"Q", "FIXED", 0.05, 0)
##calibrate by modifying the factor distribution
bottomup <- 1:3
@@ -151,9 +151,9 @@ dist <- list(L=L, R=R) write.table(data.frame(Z=Z, w=w.mod),
file=file.path(root.dir, "Scenarios", "Calibration",
- paste0("calibration-", workdate, ".csv")),
+ paste0("calibration-", tradedate, ".csv")),
col.names=T, row.names=F, sep=",")
save(singlenames.data, hy21, tranche.upf, dist,
file = file.path(root.dir, "Scenarios", "Calibration",
- paste0("marketdata-", workdate, ".RData")), compress="xz")
+ paste0("marketdata-", tradedate, ".RData")), compress="xz")
|
