aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/mlpdb.R18
1 files changed, 11 insertions, 7 deletions
diff --git a/R/mlpdb.R b/R/mlpdb.R
index f3ae8ee7..3d08fd85 100644
--- a/R/mlpdb.R
+++ b/R/mlpdb.R
@@ -50,16 +50,20 @@ indexsplit <- function(indexname){
}
get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
- sqlstr <- paste("select * from tranche_quotes where index='%s'",
- "and series=%s and quotedate::date='%s' and tenor = '%s'",
- "and quotesource='MKIT' order by attach asc")
+ sqlstr <- paste("select distinct quotesource, quotedate from tranche_quotes",
+ "where index='%s' and series=%s and quotedate::date='%s'",
+ "and tenor = '%s' order by quotedate desc")
temp <- indexsplit(indexname)
r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, date, tenor))
- if(nrow(r)==0){
+
+ if(nrow(r)>0){
sqlstr <- paste("select * from tranche_quotes where index='%s'",
- "and series=%s and quotedate::date='%s' and tenor = '%s'",
- "order by attach asc")
- r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, date, tenor))
+ "and series=%s and tenor = '%s' and quotedate='%s'",
+ "and detach-attach!=5 and quotesource='%s' order by attach asc")
+ r <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, tenor,
+ r$quotedate, r$quotesource))
+ }else{
+ stop("no quotes for that day")
}
return( r )
}