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
|
## parse command line arguments
library(logging)
basicConfig()
options(stringsAsFactors = FALSE)
source("yieldcurve.R")
source("optimization.R")
source("calibration.R")
source("serenitasdb.R")
source("creditIndex.R")
source("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))
|