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
|
## parse command line arguments
root.dir <- if(.Platform$OS.type == "unix"){
"/home/share/CorpCDOs"
}else{
"//WDSENTINEL/share/CorpCDOs"
}
library(logging)
basicConfig()
options(stringsAsFactors = FALSE)
source(file.path(root.dir, "code", "R", "yieldcurve.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
source(file.path(root.dir, "code", "R", "calibration.R"), chdir=TRUE)
source(file.path(root.dir, "code", "R", "serenitasdb.R"))
source(file.path(root.dir, "code", "R", "creditIndex.R"))
source(file.path(root.dir, "code", "R", "tranche_functions.R"))
#we load the index we want to shock
tradedate <- addBusDay(Sys.Date(), -1)
index <- load.index("hy19", "5yr", tradedate)
rho <- get.skews('HY23', '5yr')
colnames(rho) <- c("date", "15 Corr", "25 Corr", "35 Corr")
skew.shocks <- apply(log(-log(rho[,-1])), 2, diff)
pvshocks1 <- BCtranche.VaR(index, skew.shocks)
shock.spreads <- diff(log(get.indexquotes('HY', 21, '5yr')$closespread))
before <- BCtranche.pv(index)
pv.shocks2 <- t(vapply(shock.spreads, function(eps){
index$portfolio <- tweakportfolio(index$portfolio, eps)
index$defaultprob <- 1 - SPmatrix(index$portfolio, length(index$cs$dates))
return( BCtranche.pv(index)$bp-before$bp )
}, before$bp))
|