aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql31
1 files changed, 5 insertions, 26 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index 58cbb1f9..c2568878 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -147,10 +147,6 @@ CREATE TABLE cds(id serial primary key,
detach float,
clearing_facility varchar(12) DEFAULT NULL,
isda_definition isda,
- termination_date date[] DEFAULT NULL,
- termination_fee float[] DEFAULT NULL,
- termination_amount float[] DEFAULT NULL,
- termination_cp text[] DEFAULT NULL,
initial_margin_percentage float DEFAULT NULL,
index_ref float DEFAULT NULL,
corr_attach float DEFAULT NULL,
@@ -703,15 +699,14 @@ SELECT id, trade_date, security_id, security_desc, maturity, fixed_rate, currenc
orig_attach, orig_detach, attach, detach, account_code, initial_margin_percentage,
cpty_id
FROM cds LEFT JOIN (
- SELECT id, SUM(termination_amount ) AS terminated_amount
- FROM (SELECT id, unnest(termination_amount) as termination_amount,
- unnest(termination_date) as termination_date FROM cds) a
- WHERE termination_date <= p_date GROUP BY id) b USING (id)
+ SELECT dealid, SUM(termination_amount) AS terminated_amount
+ FROM terminations WHERE termination_date <= p_date GROUP BY dealid) b USING (dealid)
WHERE fund=p_fund and notional IS DISTINCT FROM terminated_amount
AND trade_date <= p_date AND maturity > p_date;
END;
$$ LANGUAGE plpgsql;
+
CREATE OR REPLACE function list_cds_positions (p_date date,
strat cds_strat DEFAULT NULL::cds_strat,
fund fund DEFAULT 'SERCGMAST'::fund)
@@ -1792,7 +1787,7 @@ FROM swaptions JOIN counterparties ON cp_code = code
LEFT JOIN index_version ON security_id = redindexcode) ORDER BY trade_date DESC;
CREATE OR REPLACE VIEW cds_trades AS
-SELECT id,
+SELECT cds.id,
dealid,
termination_date AS trade_date,
termination_amount AS notional,
@@ -1818,23 +1813,7 @@ SELECT id,
END AS protection,
termination_fee AS upfront,
ref
-FROM (select id,
- dealid,
- unnest(termination_date) AS termination_date,
- unnest(termination_amount) AS termination_amount,
- security_desc,
- security_id,
- unnest(termination_cp) AS termination_cp,
- folder,
- fund,
- orig_attach,
- orig_detach,
- attach,
- detach,
- protection,
- unnest(termination_fee) AS termination_fee,
- cp_code,
- ref from cds where termination_date is not null) a
+FROM terminations LEFT JOIN cds USING (dealid)
left JOIN counterparties on termination_cp=code
UNION ALL (
SELECT id,