aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/build_cds_database.R2
-rw-r--r--R/build_portfolios.R2
-rw-r--r--R/build_scenarios.R2
-rw-r--r--R/calibrate_tranches_BC.R6
-rw-r--r--R/calibrate_tranches_MF.R2
-rw-r--r--R/load_cds_data.R10
-rw-r--r--R/load_cf.R2
-rw-r--r--R/serenitasdb.R (renamed from R/mlpdb.R)18
8 files changed, 24 insertions, 20 deletions
diff --git a/R/build_cds_database.R b/R/build_cds_database.R
index 95696e4e..f6d5cd6e 100644
--- a/R/build_cds_database.R
+++ b/R/build_cds_database.R
@@ -1,7 +1,7 @@
library(Rbbg)
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
-dbCon <- dbConnect(drv, dbname="mlpdb", user="mlpdb_user", password="Serenitas1",
+dbCon <- dbConnect(drv, dbname="serenitasdb", user="serenitas_user", password="Serenitas1",
host="debian")
bbgConn <- blpConnect(host='192.168.1.108', port='8194')
diff --git a/R/build_portfolios.R b/R/build_portfolios.R
index 8251538c..f2657658 100644
--- a/R/build_portfolios.R
+++ b/R/build_portfolios.R
@@ -12,7 +12,7 @@ if(.Platform$OS.type == "unix"){
source(file.path(code.dir, "code", "R", "intex_deal_functions.R"), chdir=TRUE)
source(file.path(code.dir, "code", "R", "yieldcurve.R"))
-source(file.path(code.dir, "code", "R", "mlpdb.R"))
+source(file.path(code.dir, "code", "R", "serenitasdb.R"))
index <- load.index("hy21")
if(length(args) >=2){
diff --git a/R/build_scenarios.R b/R/build_scenarios.R
index e9fb0db6..1e26f62d 100644
--- a/R/build_scenarios.R
+++ b/R/build_scenarios.R
@@ -36,7 +36,7 @@ if(length(args) >=2){
source(file.path(code.dir, "code", "R", "intex_deal_functions.R"), chdir=TRUE)
source(file.path(code.dir, "code", "R", "etdb.R"))
source(file.path(code.dir, "code", "R", "yieldcurve.R"))
-source(file.path(code.dir, "code", "R", "mlpdb.R"))
+source(file.path(code.dir, "code", "R", "serenitasdb.R"))
calibration.date <- addBusDay(tradedate, -1)
settledate <- addBusDay(tradedate, 3)
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R
index 697ad998..c0c9bede 100644
--- a/R/calibrate_tranches_BC.R
+++ b/R/calibrate_tranches_BC.R
@@ -62,7 +62,7 @@ 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", "mlpdb.R"))
+source(file.path(root.dir, "code", "R", "serenitasdb.R"))
library(lossdistrib)
n.int <- 250
@@ -90,6 +90,9 @@ for(i in seq_along(runs$name)){
if(index.name=="ig19"){
alldates <- alldates[alldates!=as.Date("2013-11-29")] ##people are lazy the day after Thanksgiving
}
+ if(index.name=="hy21" & tenor =="3yr"){
+ ##alldates <- alldates[alldates!=as.Date("2013-11-29")] ##people are lazy the day after Thanksgiving
+ }
bus.dates <- as.Date(names(which(isBusinessDay(calendar="UnitedStates/GovernmentBond", alldates))))
##check if we have all the quotes and save them
@@ -100,6 +103,7 @@ for(i in seq_along(runs$name)){
quotes <- matrix(0, length(bus.dates), 2+2*n.tranches)
for(j in seq_along(bus.dates)){
tradedate <- bus.dates[j]
+ print (tradedate)
index <- load.index(index.name, tradedate, tenor, Z, w, Ngrid)
temp <- get.tranchequotes(index$name, index$tenor, tradedate)
quotes[j, 1] <- temp$indexrefprice[1]
diff --git a/R/calibrate_tranches_MF.R b/R/calibrate_tranches_MF.R
index 8b111dd5..2361398f 100644
--- a/R/calibrate_tranches_MF.R
+++ b/R/calibrate_tranches_MF.R
@@ -18,7 +18,7 @@ if(code.dir==""){
source(file.path(code.dir, "code", "R", "yieldcurve.R"))
source(file.path(code.dir, "code", "R", "optimization.R"))
source(file.path(code.dir, "code", "R", "calibration.R"), chdir=TRUE)
-source(file.path(code.dir, "code", "R", "mlpdb.R"))
+source(file.path(code.dir, "code", "R", "serenitasdb.R"))
##figure out the tradedate
if(length(args) >= 1){
diff --git a/R/load_cds_data.R b/R/load_cds_data.R
index 7c9590ff..63e74835 100644
--- a/R/load_cds_data.R
+++ b/R/load_cds_data.R
@@ -1,8 +1,8 @@
library(Rbbg)
-source("mlpdb.R")
+source("serenitasdb.R")
download.cdscurves <- function(date=Sys.Date()){
- tickers <- dbGetQuery(mlpdbCon, "select cds_curve[6] from CDS_Issuers")$cds_curve
+ tickers <- dbGetQuery(serenitasdb, "select cds_curve[6] from CDS_Issuers")$cds_curve
bbg.data <- bds(bbgConn, paste(tickers, "Curncy"), "cds_curve_info")
stmt <- "INSERT INTO cds_quotes VALUES('%s', '%s', 0, 0, %s, %s, %s, %s)"
for(i in 1:nrow(bbg.data)){
@@ -12,9 +12,9 @@ download.cdscurves <- function(date=Sys.Date()){
}else{
Source <- paste0("'", Source, "'")
}
- dbSendQuery(mlpdbCon, sprintf(stmt, format(date,"%m/%d/%y"),
- bbg.data[i,2], bbg.data[i,4], bbg.data[i,5],
- Source, bbg.data[i,6]))
+ dbSendQuery(serenitasdb, sprintf(stmt, format(date,"%m/%d/%y"),
+ bbg.data[i,2], bbg.data[i,4], bbg.data[i,5],
+ Source, bbg.data[i,6]))
}
}
diff --git a/R/load_cf.R b/R/load_cf.R
index 08c685e5..df9c8d0b 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -24,7 +24,7 @@ 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"))
-source(file.path(root.dir, "code", "R", "mlpdb.R"))
+source(file.path(root.dir, "code", "R", "serenitasdb.R"))
index <- load.index("hy21")
calibration.date <- addBusDay(tradedate, -1)
diff --git a/R/mlpdb.R b/R/serenitasdb.R
index 5778774e..80b50ed6 100644
--- a/R/mlpdb.R
+++ b/R/serenitasdb.R
@@ -1,18 +1,18 @@
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
-mlpdbCon <- dbConnect(drv, dbname="mlpdb", user="mlpdb_user", password="Serenitas1",
- host="debian")
+serenitasdb <- dbConnect(drv, dbname="serenitasdb", user="serenitas_user", password="Serenitas1",
+ host="debian")
nameToBasketID <- function(name, date=Sys.Date()){
sqlstr <- "SELECT * from nametobasketid('%s', '%s')"
- r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, name, date))
+ r <- dbGetQuery(serenitasdb, sprintf(sqlstr, name, date))
return(as.integer(r))
}
load.index <- function(name, date=Sys.Date(), tenor="5yr", Z, w, N){
id <- nameToBasketID(name, date)
sqlstr <- "SELECT indexfactor, cumulativeloss, maturity from index_desc where basketid=%s and tenor='%s'"
- r <- as.list(dbGetQuery(mlpdbCon, sprintf(sqlstr, id, tenor)))
+ r <- as.list(dbGetQuery(serenitasdb, sprintf(sqlstr, id, tenor)))
if(any(c(missing(Z), missing(w), missing(N)))){
return( list(tenor=tenor, factor=r$indexfactor/100, maturity=r$maturity,
loss=r$cumulativeloss/100, recovery=0.4, name=name))
@@ -25,7 +25,7 @@ load.index <- function(name, date=Sys.Date(), tenor="5yr", Z, w, N){
cdslist <- function(indexname, date=Sys.Date()){
basketid <- nameToBasketID(indexname, date)
sqlstr <- "select * from CDS_Issuers where index_list @> '{%s}'"
- return( dbGetQuery(mlpdbCon, sprintf(sqlstr, basketid)))
+ return( dbGetQuery(serenitasdb, sprintf(sqlstr, basketid)))
}
arr.convert <- function(arr){
@@ -37,7 +37,7 @@ arr.convert <- function(arr){
}
get.indexquotes <- function(indexname, date=Sys.Date()){
- r <- dbGetQuery(mlpdbCon, sprintf("select * from curve_quotes('%s', '%s')", indexname, date))
+ r <- dbGetQuery(serenitasdb, sprintf("select * from curve_quotes('%s', '%s')", indexname, date))
quotes <- list(tickers=r[,1],
spread_curve = arr.convert(r$spread_curve),
upfront_curve =arr.convert(r$upfront_curve),
@@ -60,7 +60,7 @@ get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
sqlstr <- paste("select * from tranche_quotes",
"where index='%s' and series=%s and quotedate::date='%s'",
"and tenor = '%s' order by attach asc")
- r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, date, tenor))
+ r <- dbGetQuery(serenitasdb, sprintf(sqlstr, temp$index, temp$series, date, tenor))
## check if set is unique and complete
## hy9 and hy10 tranche is gone
if(tolower(indexname) %in% c("hy9", "hy10")){
@@ -76,7 +76,7 @@ get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
sqlstr <- paste("select distinct quotesource, quotedate from tranche_quotes",
"where index='%s' and series=%s and quotedate::date='%s'",
"and tenor = '%s' order by quotedate desc")
- distinct.quotes <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, date, tenor))
+ distinct.quotes <- dbGetQuery(serenitasdb, sprintf(sqlstr, temp$index, temp$series, date, tenor))
flag <- FALSE
##we loop through the disctinct quotes until we find a complete set
for(i in 1:nrow(distinct.quotes)){
@@ -89,7 +89,7 @@ get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
"and series=%s and tenor = '%s' and quotedate='%s'",
"and quotesource='%s' order by attach asc")
}
- r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, tenor,
+ r <- dbGetQuery(serenitasdb, sprintf(sqlstr, temp$index, temp$series, tenor,
distinct.quotes$quotedate[i],
distinct.quotes$quotesource[i]))
if(all(c(r$attach, 100)==c(lower.attach, r$detach))){#set is complete