aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql19
1 files changed, 18 insertions, 1 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index f8d20507..935f666b 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -678,6 +678,23 @@ RETURN QUERY
END;
$$ LANGUAGE plpgsql;
+CREATE OR REPLACE function list_cds_positions_by_strat_fcm(p_date date,
+ fcm text)
+RETURNS TABLE(security_id varchar(12), security_desc varchar(32), maturity date,
+ fixed_rate float, currency currency, folder cds_strat, notional float) AS $$
+BEGIN
+RETURN QUERY
+ WITH tmp AS (SELECT cds.security_id, cds.security_desc, cds.maturity, cds.fixed_rate,
+ cds.currency, cds.folder
+ SUM(cds.notional * (CASE WHEN cds.protection='Buyer' THEN 1 ELSE -1 END))
+ OVER (PARTITION BY cds.security_id, cds.maturity, cds.folder, cds.account_code) AS notional
+ FROM cds WHERE (cds.termination_date is NULL OR cds.termination_date > p_date) AND
+ cds.trade_date <= p_date AND cds.attach is NULL AND cds.folder != 'MBSCDS'
+ AND cds.account_code=fcm::text)
+ SELECT DISTINCT ON (tmp.security_id, tmp.maturity, tmp.folder) * FROM tmp WHERE tmp.notional!=0;
+END;
+$$ LANGUAGE plpgsql;
+
CREATE OR REPLACE FUNCTION cds_globeop_name(redcode text, fixed_rate float, maturity date,
index index_type, tenor tenor)
RETURNS text AS $$
@@ -1472,7 +1489,7 @@ CREATE TYPE clearing_cp AS ENUM('ICE-CREDIT', 'NOT CLEARED');
CREATE TYPE trade_type AS ENUM('CREDIT_DEFAULT_SWAP', 'SWAPTION', 'TRANCHE');
CREATE TYPE transaction_status AS ENUM('Bilateral', 'Cleared');
CREATE TYPE calendar AS ENUM('Payment-GB,US', 'Payment-US,GB', 'Payment-EU,GB');
-CREATE TYPE clearing_broker AS ENUM('ML', 'SGFCM', 'BOMLCM');
+CREATE TYPE clearing_broker AS ENUM('ML', 'SGFCM', 'BOMLCM', 'WELLSFCM');
CREATE TYpe frequency AS ENUM('Monthly', 'Quarterly');
CREATE TABLE cds_reports(