aboutsummaryrefslogtreecommitdiffstats
path: root/R/intex_deal_functions.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/intex_deal_functions.R')
-rw-r--r--R/intex_deal_functions.R15
1 files changed, 5 insertions, 10 deletions
diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R
index 270fc07d..658cac4e 100644
--- a/R/intex_deal_functions.R
+++ b/R/intex_deal_functions.R
@@ -2,6 +2,7 @@ library(RQuantLib)
library(data.table)
library(doParallel)
library(lossdistrib)
+library(dplyr)
hostname <- system("hostname", intern=TRUE)
if(hostname=="debian"){
@@ -15,21 +16,15 @@ source("db.R")
etdb <- dbConn("ET")
getdealdata <- function(dealname, workdate){
- sqlstring <- paste0("select marketvalue from et_deal_model_numbers where dealname=$1 and ",
- "updatedate in (select max(updatedate) from et_deal_model_numbers where ",
- "dealname = $2 and updatedate<=$3)")
- mv <- dbGetQuery(etdb, sqlstring,
- params = list(dealname, dealname, workdate))$marketvalue
+ mv <- etdb %>% tbl("et_deal_model_numbers") %>%
+ filter(dealname == !!dealname, updatedate <= !! workdate) %>%
+ arrange(desc(updatedate)) %>% head(1) %>% pull(marketvalue)
sqlstring <- paste0("select \"Curr Collat Bal\", reinv_end_date, ",
"first_pay_date , maturity, \"Principal Bal\" , pay_day from ",
"historical_clo_universe($1, $2)")
dealdata <- dbGetQuery(etdb, sqlstring, params=list(dealname, workdate))
- if(!length(mv)){
- dealdata$mv <- NA
- }else{
- dealdata$mv <- mv
- }
+ dealdata$mv <- if(!length(mv)) NA else mv
return(dealdata)
}