aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql20
1 files changed, 12 insertions, 8 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index 02432d0c..8550c41f 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -1335,7 +1335,7 @@ BEGIN
RETURN QUERY
SELECT id, fund, 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)
+ (CASE WHEN cds.protection='Buy' THEN 1 ELSE -1 END)
AS notional,
orig_attach, orig_detach, attach, detach, account_code, initial_margin_percentage,
cpty_id,
@@ -1355,7 +1355,7 @@ BEGIN
RETURN QUERY
SELECT id, fund, 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)
+ (CASE WHEN cds.protection='Buy' THEN 1 ELSE -1 END)
AS notional,
orig_attach, orig_detach, attach, detach, account_code, initial_margin_percentage,
cpty_id,
@@ -3042,13 +3042,15 @@ SELECT cds.id,
orig_detach,
attach,
detach,
- CASE protection WHEN 'Buyer' THEN
- 'Seller'::protection
+ CASE protection WHEN 'Buy' THEN
+ 'Sell'::protection
ELSE
- 'Buyer'::protection
+ 'Buy'::protection
END AS protection,
termination_fee AS upfront,
- terminations.traded_level
+ terminations.traded_level,
+ terminations.fee_payment_date AS settle_date,
+ cds.currency
FROM terminations RIGHT JOIN cds USING (dealid)
LEFT JOIN counterparties on termination_cp=code
WHERE termination_date is NOT NULL
@@ -3070,7 +3072,9 @@ SELECT id,
detach,
protection,
upfront,
- traded_level
+ traded_level,
+ cds.upfront_settle_date AS settle_date,
+ cds.currency
FROM cds JOIN counterparties ON cp_code = code) ORDER BY trade_date DESC, folder;
CREATE TABLE curve_risk(
@@ -3436,7 +3440,7 @@ begin
SELECT LEFT(split_part(security_desc, ' ', 2),2) AS "index", imm.tradeid, a.fund, pfm.clean_folder, pfm.portfolio, a.security_id, a.notional, a.fcm
FROM (
SELECT cds.fund, account_code AS fcm, cds.security_id, max(security_desc) AS security_desc, maturity, folder,
-SUM(cds.notional * (CASE WHEN protection='Buyer' THEN 1 ELSE -1 END)) AS notional FROM cds
+SUM(cds.notional * (CASE WHEN protection='Buy' THEN 1 ELSE -1 END)) AS notional FROM cds
WHERE swap_type='CD_INDEX' AND trade_date<=start_from AND maturity > start_from
GROUP BY cds.security_id, maturity, cds.folder, cds.fund, account_code) a
LEFT JOIN portfolio_folder_mapping pfm ON replace(a.folder::text, 'SER_', '')=pfm.clean_folder