aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/serenitasdb.R35
1 files changed, 15 insertions, 20 deletions
diff --git a/R/serenitasdb.R b/R/serenitasdb.R
index 04a6224a..798c55f8 100644
--- a/R/serenitasdb.R
+++ b/R/serenitasdb.R
@@ -79,9 +79,11 @@ get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
sqlstr <- paste("select * from tranche_quotes",
"where index=$1 and series=$2 and quotedate::date=$3",
"and tenor = $4 order by attach asc")
- r <- with(indexsplit(indexname),
- dbGetQuery(serenitasdb, sqlstr,
- params = list(indextype, series, date, tenor)))
+ temp <- indexsplit(indexname)
+ indextype <- temp$indextype
+ series <- temp$series
+ r <- dbGetQuery(serenitasdb, sqlstr,
+ params = list(indextype, series, date, tenor))
## check if set is unique and complete
## hy9 and hy10 tranche is gone
if(tolower(indexname) %in% c("hy9", "hy10")){
@@ -97,29 +99,22 @@ get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
sqlstr <- paste("select distinct quotesource, quotedate from tranche_quotes",
"where index=$1 and series=$2 and quotedate::date=$3",
"and tenor = $4 order by quotedate desc")
- distinct.quotes <- with(indexsplit(indexname),
- dbGetQuery(serenitasdb, sqlstr,
- params = list(indextype, series, date, tenor)))
+ distinct.quotes <- dbGetQuery(serenitasdb, sqlstr,
+ params = list(indextype, series, date, tenor))
flag <- FALSE
##we loop through the disctinct quotes until we find a complete set
if(nrow(distinct.quotes)==0){
return(NULL)
}
for(i in 1:nrow(distinct.quotes)){
- if(temp$index == 'HY' && temp$series>=15){ ##don't want the tranchelets quoted by CITI
- sqlstr <- paste("select * from tranche_quotes where index=$1",
- "and series=$2 and tenor = $3 and quotedate=$4",
- "and detach-attach!=5 and quotesource=$5 order by attach asc")
- }else{
- sqlstr <- paste("select * from tranche_quotes where index=$1",
- "and series=$2 and tenor = $3 and quotedate=$4",
- "and quotesource=$5 order by attach asc")
- }
- r <- with(indexsplit(indexname),
- dbGetQuery(serenitasdb, sqlstr,
- params = list(indextype, series, tenor,
- distinct.quotes$quotedate[i],
- distinct.quotes$quotesource[i])))
+ sqlstr <- str_c("select * from tranche_quotes where index=$1 ",
+ "and series=$2 and tenor = $3 and quotedate=$4 ",
+ if(indextype == 'HY' && series>=15) "and detach-attach!=5 " else NULL,
+ "and quotesource=$5 order by attach asc")
+ r <- dbGetQuery(serenitasdb, sqlstr,
+ params = list(indextype, series, tenor,
+ distinct.quotes$quotedate[i],
+ distinct.quotes$quotesource[i]))
if(all(c(r$attach, 100)==c(lower.attach, r$detach))){#set is complete
flag <- TRUE
break