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, 19 insertions, 0 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index b2707cc3..fc01d1bd 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -1030,6 +1030,25 @@ WHERE fund=p_fund and notional IS DISTINCT FROM terminated_amount
END;
$$ LANGUAGE plpgsql;
+CREATE OR REPLACE function list_cds2(p_date date, p_fund fund DEFAULT 'SERCGMAST'::fund)
+-- Do not include unsettled terminations
+RETURNS SETOF LIST_CDS AS $$
+BEGIN
+RETURN QUERY
+SELECT id, trade_date, security_id, security_desc, maturity, fixed_rate, currency,
+ folder, protection, (notional - coalesce(terminated_amount, 0.)) *
+ (CASE WHEN cds.protection='Buyer' THEN 1 ELSE -1 END)
+ AS notional,
+ orig_attach, orig_detach, attach, detach, account_code, initial_margin_percentage,
+ cpty_id,
+ cp_code
+FROM cds LEFT JOIN (
+ SELECT dealid, SUM(termination_amount) AS terminated_amount
+ FROM terminations WHERE fee_payment_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,