aboutsummaryrefslogtreecommitdiffstats
path: root/sql/quantifi.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/quantifi.sql')
-rw-r--r--sql/quantifi.sql20
1 files changed, 20 insertions, 0 deletions
diff --git a/sql/quantifi.sql b/sql/quantifi.sql
index 17fe1d95..2bce202d 100644
--- a/sql/quantifi.sql
+++ b/sql/quantifi.sql
@@ -321,3 +321,23 @@ CREATE TABLE swaptions (
CREATE SERVER dawndb_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (dbname 'dawndb');
CREATE USER MAPPING FOR quantifi_user SERVER dawndb_server OPTIONS (user 'dawn_user', password '****');
+
+CREATE OR REPLACE
+FUNCTION list_unterminated_tranche(p_start_from date) RETURNS TABLE (date date, productname TEXT, tradeid TEXT) AS $$
+BEGIN
+ RETURN query
+ SELECT ct.date, a.productname, ct.tradeid
+FROM(
+ SELECT c.productname, sum(currentnotional)
+FROM cdxtrancheut c
+WHERE c.date = p_start_from
+GROUP BY
+ c.productname
+HAVING
+ sum(currentnotional)= 0) a
+LEFT JOIN cdxtrancheut ct
+ USING (productname);
+
+END;
+
+$$ LANGUAGE plpgsql; \ No newline at end of file