1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/usr/bin/Rscript
require(methods)
library(lossdistrib)
options(warn=2)
args <- commandArgs(trailingOnly=TRUE)
if(.Platform$OS.type == "unix"){
root.dir <- "/home/share/CorpCDOs"
}else{
root.dir <- "//WDSENTINEL/share/CorpCDOs"
}
code.dir <- Sys.getenv("CODE_DIR")
if(code.dir==""){
code.dir<-root.dir
}
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", "mlpdb.R"))
##figure out the tradedate
if(length(args) >= 1){
tradedate <- as.Date(args[1])
}else{
tradedate <- addBusDay(Sys.Date(), -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 <- 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),
file=file.path(root.dir, "Scenarios", "Calibration",
paste0("calibration-", tradedate, ".csv")),
col.names=T, row.names=F, sep=",")
save(index, dist, file = file.path(root.dir, "Scenarios", "Calibration",
paste0("marketdata-", tradedate, ".RData")), compress="xz")
|