diff options
| -rw-r--r-- | R/load_cf.R | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/R/load_cf.R b/R/load_cf.R index 8fd7fb25..1d932074 100644 --- a/R/load_cf.R +++ b/R/load_cf.R @@ -15,7 +15,7 @@ tradedate <- if(length(args) >= 1) as.Date(args[1]) else Sys.Date() source(file.path(root.dir, "code", "R", "yieldcurve.R"))
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", "intex_deal_functions.R"), chdir=TRUE)
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", "serenitasdb.R"))
@@ -303,6 +303,7 @@ for(dealname in names(cfdata)){ }
## upload model data
+dawndb <- dbConn("dawndb")
for(cusip in names(cusipdata)){
sqlstring <- paste0("SELECT updatedate from et_cusip_model_numbers",
" WHERE cusip=$1")
@@ -318,9 +319,30 @@ for(cusip in names(cusipdata)){ sqlstring <- paste0("INSERT INTO et_cusip_model_numbers ",
"VALUES($1, $2, $3, $4, $5, $6)")
params <- c(cusip, values, as.character(tradedate))
+
}
r <- dbSendQuery(etdb, sqlstring, params=params)
if(dbHasCompleted(r)){
dbClearResult(r)
}
+ identifier <- dbGetQuery(dawndb, "SELECT identifier from securities WHERE cusip=$1",
+ params=list(cusip))
+ identifier <- if(nrow(identifier)>0) identifier$identifier else NULL
+ cat(identifier, "\n")
+ if(!is.null(identifier)){
+ if(nrow(sqldata) && (tradedate %in% as.Date(sqldata$updatedate))){
+ params <- c(values, identifier, as.character(tradedate))
+ sqlstring <- paste0("UPDATE risk_numbers SET model_price=$1, wal=$2, duration=$3,",
+ "index_delta='HY',delta=$4 WHERE identifier=$5 and date=$6")
+ }else{
+ sqlstring <- paste0("INSERT INTO risk_numbers(identifier, date, index_delta,",
+ "model_price, wal, duration, delta) ",
+ "VALUES($1, $2, $3, $4, $5, $6, $7)")
+ params <- c(identifier, as.character(tradedate), 'HY', values)
+ }
+ r <- dbSendQuery(dawndb, sqlstring, params=params)
+ if(dbHasCompleted(r)){
+ dbClearResult(r)
+ }
+ }
}
|
