aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/VaR.R34
1 files changed, 34 insertions, 0 deletions
diff --git a/R/VaR.R b/R/VaR.R
new file mode 100644
index 00000000..a329abd7
--- /dev/null
+++ b/R/VaR.R
@@ -0,0 +1,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 <- addBusDays(Sys.Date(), -1)
+index <- load.index("hy19", "5yr", tradedate)
+
+rho <- get.skews('HY', 23, '5yr')
+colnames(rho) <- c("15 Corr", "25 Corr", "35 Corr")
+skew.shocks <- apply(log(-log(rho)), 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))