diff options
Diffstat (limited to 'R/new_index_series.R')
| -rw-r--r-- | R/new_index_series.R | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/R/new_index_series.R b/R/new_index_series.R index d6854667..b4b611cc 100644 --- a/R/new_index_series.R +++ b/R/new_index_series.R @@ -1,5 +1,6 @@ library(Rbbg) library(RPostgreSQL) +library(lubridate) drv <- dbDriver("PostgreSQL") dbCon <- dbConnect(drv, dbname="serenitasdb", user="serenitas_user", password="Serenitas1", host="debian") @@ -7,20 +8,29 @@ dbCon <- dbConnect(drv, dbname="serenitasdb", user="serenitas_user", password="S bbgConn <- blpConnect(host='192.168.1.108', port='8194') ## This script helps adding the necessary data for a new index series -newbasketID <- function(indextype='IG', series, newid){ - sqlstr <- "INSERT INTO index_version VALUES(%s, '%s', %s, '%s', '%s', 100, 0)" - stmt <- sprintf(sqlstr, newid, indextype, series, 1, 100, 0, 'infinity') +newbasketID <- function(indextype='IG', series, mat_5yr, coupon){ + sqlstr <- paste("INSERT INTO index_version(index, series, version, indexfactor, cumulativeloss, lastdate)", + "VALUES('%s', %s, %s, 100, 0, 'infinity')") + stmt <- sprintf(sqlstr, indextype, series, 1) dbSendQuery(dbCon, stmt) + maturity <- mat_5yr + years(c(-2, 0, 2 ,5)) + tenor <- c("3yr", "5yr", "7yr", "10yr") + sqlstr <- "INSERT INTO index_maturity VALUES('%s', %s, '%s', '%s', %s)" + for(i in seq_along(tenor)){ + stmt <- sprintf(sqlstr, indextype, series, tenor[i], maturity[i], coupon) + dbSendQuery(dbCon, stmt) + } } + ##TODO: fill the index -indextype <- 'IG' +indexname <- 'ITRX' ## or CDX +indextype <- 'XOVER' ## or IG or HY oldseries <- 22 newseries <- 23 -newid <- 338 -newbasketID('IG', 23, 338) +newbasketID('IG', 23, as.Date("2019-12-20")) -oldindex <- bds(bbgConn, sprintf("CDX %s CDSI S%s 5Y Corp", indextype, oldseries), "INDX_MEMBERS") -newindex <- bds(bbgConn, sprintf("CDX %s CDSI S%s 5Y Corp", indextype, newseries), "INDX_MEMBERS") +oldindex <- bds(bbgConn, sprintf("%s %s CDSI S%s 5Y Corp", indexname, indextype, oldseries), "INDX_MEMBERS") +newindex <- bds(bbgConn, sprintf("%s %s CDSI S%s 5Y Corp", indexname, indextype, newseries), "INDX_MEMBERS") oldtickers <- oldindex[,5] tickers <- newindex[,5] |
