diff options
| -rw-r--r-- | R/calibrate_tranches.R | 22 | ||||
| -rw-r--r-- | R/cds_functions_generic.R | 14 |
2 files changed, 12 insertions, 24 deletions
diff --git a/R/calibrate_tranches.R b/R/calibrate_tranches.R index 3e2599fc..178f23ae 100644 --- a/R/calibrate_tranches.R +++ b/R/calibrate_tranches.R @@ -1,11 +1,11 @@ library("parallel")
-setwd("//WDSENTINEL/share/CorpCDOs/R")
-source("cds_utils.R")
-source("cds_functions_generic.R")
-source("index_definitions.R")
-source("tranche_functions.R")
-source("yieldcurve.R")
-source("optimization.R")
+root.dir <- "//WDSENTINEL/share/CorpCDOs/"
+source(file.path(root.dir, "code", "R", "cds_utils.R"))
+source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
+source(file.path(root.dir, "code", "R", "index_definitions.R"))
+source(file.path(root.dir, "code", "R", "tranche_functions.R"))
+source(file.path(root.dir, "code", "R", "yieldcurve.R"))
+source(file.path(root.dir, "code", "R", "optimization.R"))
cl <- makeCluster(6)
@@ -19,7 +19,7 @@ setEvaluationDate(as.Date(MarkitData$effectiveasof)) ## calibrate HY19
## calibrate the single names curves
singlenames.data <- read.table(file="clipboard", sep="\t", header=T)
-nondefaulted <- singlenames.data[!singlenames.data$ticker %in% hy17$defaulted,]
+nondefaulted <- singlenames.data[!singlenames.data$ticker %in% hy19$defaulted,]
bps <- 1e-4
cdsdates <- as.Date(character(0))
@@ -66,7 +66,7 @@ SurvProb <- SPmatrix(hy19portfolio.tweaked, hy19) ## load common parameters
K <- c(0, 0.15, 0.25, 0.35, 1)
Kmodified <- adjust.attachments(K, hy19$loss, hy19$factor)
-tranche.upf <- c(37.5625, 87.25, 101.8125, 115.0625)
+tranche.upf <- c(37.8125, 87.375, 102.125, 114.96875)
tranche.running <- c(0.05, 0.05, 0.05, 0.05)
Ngrid <- 2*nrow(nondefaulted)+1
@@ -118,7 +118,7 @@ clusterExport(cl, list("shockprob", "issuerweights", "rho", "Z", "lossrecovdist. parf <- function(i){
pshocked <- apply(p, 2, shockprob, rho=rho, Z=Z[i])
S <- 1 - Rstoch[i,,]
- dist <- lossrecovdist.term(pshocked,, issuerweights, S, Ngrid)
+ dist <- lossrecovdist.term(pshocked, , issuerweights, S, Ngrid)
return( tranche.pvvec(Kmodified, dist$L, dist$R, cs))
}
@@ -152,7 +152,7 @@ for(l in 1:100){ cat(err,"\n")
}
-write.table(data.frame(Z=Z, w=w.mod), file=paste0("calibration-", Sys.Date(), ".csv"), col.names=T, row.names=F, sep=",")
+write.table(data.frame(Z=Z, w=w.mod), file=file.path(root.dir, "Scenarios", paste0("calibration-", Sys.Date(), ".csv")), col.names=T, row.names=F, sep=",")
## computes MFdeltas
newportf <- hy19portfolio.tweaked
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 8ad7e5c7..9f31d226 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -161,16 +161,6 @@ setMethod("dcouponleg", signature("data.frame", "shapedcurve", "missing"), ## return( as.numeric(crossprod(dSPadj, cs$coupons * cs$df)) )
## })
-## test.shape <- splinefun(0:5, rep(1,6))
-## eps <- 1e-8
-## test.sc.flat <- new("flatcurve", h=0.07)
-## test.sc <- new("shapedcurve", h=0.07, shape=test.shape, alpha=.25, beta=15)
-## test.scplus <- new("shapedcurve", h=0.07+eps, shape=test.shape, alpha=.25, beta=15)
-## test.scminus <- new("shapedcurve", h=0.07-eps, shape=test.shape, alpha=.25, beta=15)
-
-## (couponleg(cs, test.scplus)-couponleg(cs, test.scminus))/(2 * eps)
-
-
## define cdsduration generic
setGeneric("cdsduration", function(sc, maturity, ...) {
standardGeneric("cdsduration")
@@ -545,6 +535,7 @@ portfoliospread <- function(portfolio, maturity){ S <- S/sum(d)
return(S)
}
+
tweakcurves <- function(portfolio, index){
## computes the tweaking factor
epsilon <- 0
@@ -673,6 +664,3 @@ forwardportfolioprice <- function(portfolio, startdate, rollingmaturity, coupont }
return(mean(r))
}
-
-portfoliospread <- function
-
|
