diff options
| -rw-r--r-- | R/build_portfolios.R | 1 | ||||
| -rw-r--r-- | R/build_scenarios.R | 3 | ||||
| -rw-r--r-- | R/load_cf.R | 5 | ||||
| -rw-r--r-- | R/mlpdb.R | 12 | ||||
| -rw-r--r-- | R/script_calibrate_tranches.R | 7 |
5 files changed, 16 insertions, 12 deletions
diff --git a/R/build_portfolios.R b/R/build_portfolios.R index f7da2e25..7c7687b5 100644 --- a/R/build_portfolios.R +++ b/R/build_portfolios.R @@ -13,6 +13,7 @@ source(file.path(root.dir, "code", "R", "intex_deal_functions.R")) 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", "yieldcurve.R"))
+source(file.path(root.dir, "code", "R", "mlpdb.R"))
hy21 <- load.index("hy21")
if(length(args) >=2){
diff --git a/R/build_scenarios.R b/R/build_scenarios.R index 5cf54d83..d0dcd8bc 100644 --- a/R/build_scenarios.R +++ b/R/build_scenarios.R @@ -40,7 +40,8 @@ source(file.path(root.dir, "code", "R", "etdb.R")) source(file.path(root.dir, "code", "R", "cds_functions_generic.R"))
source(file.path(root.dir, "code", "R", "cds_utils.R"))
source(file.path(root.dir, "code", "R", "yieldcurve.R"))
-load.index("hy21")
+source(file.path(root.dir, "code", "R", "mlpdb.R"))
+hy21 <- load.index("hy21")
calibration.date <- addBusDay(tradedate, -1)
settledate <- addBusDay(tradedate, 3)
diff --git a/R/load_cf.R b/R/load_cf.R index d3b8bcd5..8d806bb8 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -24,7 +24,8 @@ source(file.path(root.dir, "code", "R", "cds_utils.R")) source(file.path(root.dir, "code", "R", "intex_deal_functions.R"))
source(file.path(root.dir, "code", "R", "optimization.R"))
source(file.path(root.dir, "code", "R", "interpweights.R"))
-load.index("hy21")
+source(file.path(root.dir, "code", "R", "mlpdb.R"))
+index <- load.index("hy21")
calibration.date <- addBusDay(tradedate, -1)
exportYC(calibration.date)
@@ -227,7 +228,7 @@ compute.delta <- function(indexdist, dealweight, cusip.pv, tradedate=Sys.Date(), calibration.date <- addBusDay(tradedate)
## we assume the index is fully funded - need to be changed depending
## on how we fund the swaps (hence floating coupon instead of fixed)
- cs <- couponSchedule(IMMDate(tradedate), hy21$maturity, "Q",
+ cs <- couponSchedule(IMMDate(tradedate), index$maturity, "Q",
"FLOAT", 0.05, 0, calibration.date)
nT <- dim(indexdist$L)[2]
Ngrid <- dim(indexdist$L)[1]
@@ -1,18 +1,18 @@ library(RPostgreSQL) drv <- dbDriver("PostgreSQL") -dbCon <- dbConnect(drv, dbname="mlpdb", user="mlpdb_user", password="Serenitas1", +mlpdbCon <- dbConnect(drv, dbname="mlpdb", user="mlpdb_user", password="Serenitas1", host="debian") nameToBasketID <- function(name, date){ sqlstr <- "SELECT * from nametobasketid('%s', '%s')" - r <- dbGetQuery(dbCon, sprintf(sqlstr, name, date)) + r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, name, date)) return(as.integer(r)) } -load.index <- function(name, date, tenor="Y5"){ +load.index <- function(name, date=Sys.Date(), tenor="5yr"){ id <- nameToBasketID(name, date) sqlstr <- "SELECT indexfactor, cumulativeloss, maturity from index_desc where basketid=%s and tenor='%s'" - r <- as.list(dbGetQuery(dbCon, sprintf(sqlstr, id, tenor))) + r <- as.list(dbGetQuery(mlpdbCon, sprintf(sqlstr, id, tenor))) return(list(coupon=0.05, factor=r$indexfactor/100, maturity=r$maturity, loss=r$cumulativeloss/100, recovery=0.4, name=name)) } @@ -20,7 +20,7 @@ load.index <- function(name, date, tenor="Y5"){ cdslist <- function(indexname, date){ basketid <- nameToBasketID(indexname, date) sqlstr <- "select * from CDS_Issuers where index_list @> '{%s}'" - return( dbGetQuery(dbCon, sprintf(sqlstr, basketid))) + return( dbGetQuery(mlpdbCon, sprintf(sqlstr, basketid))) } arr.convert <- function(arr){ @@ -28,7 +28,7 @@ arr.convert <- function(arr){ } get.indexquotes <- function(indexname, date){ - r <- dbGetQuery(dbCon, sprintf("select * from curve_quotes('%s', '%s')", indexname, date)) + r <- dbGetQuery(mlpdbCon, sprintf("select * from curve_quotes('%s', '%s')", indexname, date)) r <- data.frame(r[,1], matrix(arr.convert(r[,2]), nrow(r), 8, byrow=T)) colnames(r) <- c("ticker", "6m", "1y", "2y", "3y", "4y", "5y", "7y", "10y") return( r ) diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R index 12cb51f7..7b095924 100644 --- a/R/script_calibrate_tranches.R +++ b/R/script_calibrate_tranches.R @@ -16,7 +16,8 @@ source(file.path(root.dir, "code", "R", "cds_functions_generic.R")) 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"))
-load.index("hy21")
+source(file.path(root.dir, "code", "R", "mlpdb.R"))
+hy21 <- load.index("hy21")
##figure out the tradedate
if(length(args) >= 1){
@@ -28,8 +29,8 @@ if(length(args) >= 1){ exportYC(tradedate)
## calibrate HY21
## calibrate the single names curves
-set.singlenamesdata(hy21, tradedate)
-set.tranchedata(hy21, tradedate)
+hy21 <- set.singlenamesdata(hy21, tradedate)
+hy21 <- set.tranchedata(hy21, tradedate)
## load tranche data
n.credit <- length(hy21$portfolio)
|
