aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/new_index_series.R7
1 files changed, 5 insertions, 2 deletions
diff --git a/R/new_index_series.R b/R/new_index_series.R
index 238a7f90..1f87fbc5 100644
--- a/R/new_index_series.R
+++ b/R/new_index_series.R
@@ -19,16 +19,19 @@ bbgname <- function(indextype, series, tenor="5Y"){
return( sprintf("%s %s CDSI S%s %s Corp", indexname, indextype, series, tenor) )
}
-newbasketID <- function(indextype='IG', series, version=1, mat_5yr, coupon){
+newbasketID <- function(indextype='IG', series, version=1, mat_5yr, coupon, red){
sqlstr <- paste0("INSERT INTO index_version",
"(index, series, version, indexfactor, cumulativeloss, lastdate, redindexcode) ",
"VALUES($1, $2, $3, 100, 0, 'infinity', $4) RETURNING basketid")
- red <- bdp(bbgname(indextype, series), "CDS_RED_PAIR_CODE")$CDS_RED_PAIR_CODE
+ if(missing(red)) {
+ red <- bdp(bbgname(indextype, series), "CDS_RED_PAIR_CODE")$CDS_RED_PAIR_CODE
+ }
basketid <- as.integer(dbGetQuery(serenitasdb, sqlstr,
params=list(indextype, series, version, red))$basketid)
maturity <- mat_5yr + lubridate::years(c(-2, 0, 2 ,5))
tenor <- c("3yr", "5yr", "7yr", "10yr")
sqlstr <- "INSERT INTO index_maturity VALUES($1, $2, $3, $4, $5)"
+ ## TODO: add issue date
for(i in seq_along(tenor)){
r <- dbSendQuery(serenitasdb, sqlstr,
params=list(indextype, series, tenor[i], maturity[i], coupon))