diff options
Diffstat (limited to 'sql/dawn.sql')
| -rw-r--r-- | sql/dawn.sql | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql index f0e09836..e4d80e57 100644 --- a/sql/dawn.sql +++ b/sql/dawn.sql @@ -1051,16 +1051,17 @@ CREATE OR REPLACE FUNCTION public.list_ir_capfloor_positions(p_date date, p_fund RETURNS TABLE(deal_id character varying, strategy swaption_strat, amount double precision, cap_or_floor cap_or_floor, strike double precision, floating_rate_index character varying, expiration_date date, initial_margin_percentage double precision, - comments character varying, cp_code character varying) AS $$ + comments character varying, cp_code character varying, nav double precision ) AS $$ BEGIN RETURN QUERY SELECT a.dealid, folder, (CASE WHEN buysell = 't' THEN 1 ELSE -1 END) * (a.amount - coalesce(terminated_amount, 0.)), a.cap_or_floor, a.strike, a.floating_rate_index, a.expiration_date, a.initial_margin_percentage, - a.comments, a.cp_code + a.comments, a.cp_code, c.nav FROM capfloors a LEFT JOIN (SELECT dealid, SUM(termination_amount) AS terminated_amount FROM terminations WHERE termination_date <= p_date GROUP BY dealid) b USING (dealid) +LEFT join (select * from external_marks_deriv where date = p_date) c on a.cpty_id = c.identifier WHERE a.amount IS DISTINCT FROM terminated_amount AND a.expiration_date > p_date AND a.trade_date <= p_date @@ -1071,15 +1072,17 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION list_ir_swaption_positions(IN p_date date, p_fund fund DEFAULT 'SERCGMAST'::fund) RETURNS TABLE(deal_id character varying, strategy swaption_strat, notional double precision, option_type option_type, strike double precision, security_id varchar, expiration_date date, maturity date, - initial_margin_percentage double precision) AS $$ + initial_margin_percentage double precision, cp_code character varying, nav double precision) AS $$ BEGIN RETURN QUERY SELECT a.dealid, folder, (CASE WHEN buysell = 't' THEN 1 ELSE -1 END) * (a.notional - coalesce(terminated_amount, 0.)), -a.option_type, a.strike, a.security_id, a.expiration_date, a.maturity, a.initial_margin_percentage + a.option_type, a.strike, a.security_id, a.expiration_date, a.maturity, a.initial_margin_percentage, + a.cp_code, c.nav FROM swaptions a LEFT JOIN (SELECT dealid, SUM(termination_amount) AS terminated_amount FROM terminations WHERE termination_date <= p_date GROUP BY dealid) b USING (dealid) +LEFT join (select * from external_marks_deriv where date = p_date) c on a.cpty_id = c.identifier WHERE a.notional IS DISTINCT FROM terminated_amount AND a.expiration_date > p_date AND a.trade_date <= p_date |
