aboutsummaryrefslogtreecommitdiffstats
path: root/R/mlpdb.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/mlpdb.R')
-rw-r--r--R/mlpdb.R23
1 files changed, 15 insertions, 8 deletions
diff --git a/R/mlpdb.R b/R/mlpdb.R
index 3d08fd85..d28e73c7 100644
--- a/R/mlpdb.R
+++ b/R/mlpdb.R
@@ -54,14 +54,21 @@ get.tranchequotes <- function(indexname, tenor='5yr', date=Sys.Date()){
"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){
- sqlstr <- paste("select * from tranche_quotes where index='%s'",
- "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))
+ ##we get the list of distinct quotes
+ distinct.quotes <- dbGetQuery(mlpdbCon, sprintf(sqlstr, temp$index, temp$series, date, tenor))
+ if(nrow(distinct.quotes)>0){
+ #we loop through the disctinct quotes until we find a complete set
+ for(i in 1:nrow(distinct.quotes)){
+ sqlstr <- paste("select * from tranche_quotes where index='%s'",
+ "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,
+ distinct.quotes$quotedate[i],
+ distinct.quotes$quotesource[i]))
+ if(all(c(r$attach, 100)==c(0, r$detach))){#set is complete
+ break
+ }
+ }
}else{
stop("no quotes for that day")
}