diff options
| -rw-r--r-- | sql/dawn.sql | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql index 8fb4423c..32b342ea 100644 --- a/sql/dawn.sql +++ b/sql/dawn.sql @@ -3830,4 +3830,51 @@ CREATE TABLE custodian_wires( currency currency, amount float8 NOT NULL, wire_details text, - unique_ref text PRIMARY KEY);
\ No newline at end of file + unique_ref text PRIMARY KEY); + + + +CREATE OR REPLACE VIEW trs_trades AS +SELECT trs.id, + dealid, + termination_date AS trade_date, + termination_amount AS notional, + underlying_desc, + underlying_security, + CASE WHEN termination_cp=cp_code THEN + 'Termination' + ELSE + 'Assignment' + END AS trade_type, + folder, + fund, + termination_cp AS cp_code, + name, + funding_index, + CASE WHEN buysell THEN + False + ELSE + True + END AS buysell, + termination_fee AS upfront, + terminations.traded_level as price +FROM terminations RIGHT JOIN trs USING (dealid) +LEFT JOIN counterparties on termination_cp=code +WHERE termination_date is NOT NULL +UNION ALL ( +SELECT id, + dealid, + trade_date, + notional, + underlying_desc, + underlying_security, + 'New', + folder, + fund, + cp_code, + name, + funding_index, + buysell, + accrued as upfront, + price +FROM trs JOIN counterparties ON cp_code = code) ORDER BY trade_date DESC, folder;
\ No newline at end of file |
