diff options
Diffstat (limited to 'sql/serenitasdb.sql')
| -rw-r--r-- | sql/serenitasdb.sql | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/sql/serenitasdb.sql b/sql/serenitasdb.sql index 96ef9167..4a024f2e 100644 --- a/sql/serenitasdb.sql +++ b/sql/serenitasdb.sql @@ -692,9 +692,9 @@ $$ END IF;
flag := FALSE;
FOR r in EXECUTE
- 'SELECT DISTINCT quotesource, quotedate FROM tranche_quotes
+ 'SELECT quotesource, quoteset FROM tranche_quotes_ref
WHERE index=$1::index_type AND series=$2 AND date(timezone(''localtime'', quotedate))=$3
- AND tenor =$4::tenor AND NOT deleted ORDER BY quotedate desc'
+ AND tenor =$4::tenor ORDER BY quotedate desc'
USING pg_index_type, pg_series, pg_date, pg_tenor LOOP
-- The JPM quotes are untriggered whereas Citi quotes are triggered
IF pg_index_type = 'XO' AND pg_series = 22 AND
@@ -704,16 +704,15 @@ $$ IF r.quotesource = 'MSre' THEN
CONTINUE;
END IF;
- If r.quotesource != source and source is not null THEN
+ If r.quotesource != source AND source IS NOT NULL THEN
CONTINUE;
END IF;
EXECUTE
- 'SELECT array_agg(attach ORDER BY attach ASC)||100::smallint = $6||array_agg(detach ORDER BY detach ASC)
- FROM tranche_quotes
- WHERE index=$1::index_type AND series=$2 AND tenor=$3::tenor
- AND quotedate=$4 AND detach-attach!=5::smallint AND quotesource=$5 AND NOT deleted'
+ 'SELECT array_agg(attach ORDER BY attach ASC)||100::smallint = $1||array_agg(detach ORDER BY detach ASC)
+ FROM tranche_quotes_tranches
+ WHERE quoteset=$1 AND NOT deleted'
INTO flag
- USING pg_index_type, pg_series, pg_tenor, r.quotedate, r.quotesource, lower_attach;
+ USING r.quoteset, lower_attach;
IF flag THEN
best_quote := r;
END IF;
@@ -724,14 +723,10 @@ $$ END IF;
IF pg_index_type = 'HY' AND pg_series >=15 THEN
RETURN QUERY
- SELECT * FROM tranche_quotes WHERE index=pg_index_type::index_type AND series= pg_series
- AND tenor=pg_tenor::tenor AND quotedate=best_quote.quotedate AND detach-attach!=5::smallint AND
- quotesource=best_quote.quotesource AND NOT deleted ORDER BY attach ASC;
+ SELECT * FROM tranche_quotes WHERE quoteset=r.quoteset AND detach-attach != 5 AND NOT deleted ORDER BY attach ASC;
ELSE
RETURN QUERY
- SELECT * FROM tranche_quotes WHERE index=pg_index_type::index_type AND series=pg_series
- AND tenor=pg_tenor::tenor AND quotedate=best_quote.quotedate AND quotesource=best_quote.quotesource AND NOT deleted
- ORDER BY attach asc;
+ SELECT * FROM tranche_quotes WHERE quoteset = r.quoteset AND NOT deleted ORDER BY attach ASC;
END IF;
END;
$$ language plpgsql;
|
