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
50
|
#!/usr/bin/Rscript
require(methods)
library(logging)
args <- commandArgs(trailingOnly=TRUE)
if(.Platform$OS.type == "unix"){
root.dir <- "/home/share/CorpCDOs"
}else{
root.dir <- "//WDSENTINEL/share/CorpCDOs"
}
basicConfig()
removeHandler('basic.stdout')
addHandler(writeToFile, file=file.path(root.dir, "logs", "calibrate_tranches_MF.log"))
options(warn=2)
code.dir <- if(Sys.getenv("CODE_DIR")!="") Sys.getenv("CODE_DIR") else 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", "serenitasdb.R"))
source(file.path(code.dir, "code", "R", "creditIndex.R"))
source(file.path(code.dir, "code", "R", "tranche_functions.R"))
##figure out the tradedate
if(length(args) >= 1){
tradedate <- as.Date(args[1])
}else{
tradedate <- addBusDay(Sys.Date(), -1)
}
exportYC(tradedate)
## calibrate HY23
## calibrate the single names curves
index <- creditIndex("hy23", "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=index$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")
|