aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql13
1 files changed, 4 insertions, 9 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index 41a459d9..d2286e23 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -605,21 +605,17 @@ LEFT JOIN risk_num USING (series, attach, detach, tenor);
END
$$ LANGUAGE plpgsql;
-CREATE OR REPLACE function list_swaption_positions_and_risks (p_date date)
-RETURNS TABLE(deal_id varchar(28), security_id varchar(12), notional float,
- swaption_type swaption_type, strike float, expiration_date date,
- market_value float, initial_margin_percentage float,
- latest_model_date date, delta float, gamma float, vega float, theta float,
- index index_type, series smallint, tenor tenor, duration float) AS $$
+CREATE OR REPLACE FUNCTION list_swaption_positions_and_risks(IN p_date date)
+ RETURNS TABLE(deal_id character varying, security_id character varying, maturity date, notional double precision, swaption_type swaption_type, strike double precision, expiration_date date, market_value double precision, initial_margin_percentage double precision, latest_model_date date, delta double precision, gamma double precision, vega double precision, theta double precision, index index_type, series smallint, tenor tenor, duration double precision) AS $$
BEGIN
RETURN QUERY
-SELECT DISTINCT ON (a.dealid) a.dealid, a.security_id,
+SELECT DISTINCT ON (a.dealid) a.dealid, a.security_id, c.maturity,
(CASE WHEN buysell = 't' THEN 1 ELSE -1 END) * a.notional,
a.swaption_type, a.strike, a.expiration_date, b.market_value,
a.initial_margin_percentage, b.date, b.delta, b.gamma, b.vega,
b.theta, c.index, c.series, c.tenor, d.duration
FROM swaptions a
-JOIN swaption_marks b USING (dealid)
+JOIN (SELECT * FROM swaption_marks where date <= p_date) b USING (dealid)
JOIN index_desc c ON a.security_id=redindexcode AND a.maturity=c.maturity
LEFT JOIN (SELECT * FROM index_quotes WHERE date=p_date) d USING (index, series, tenor, version)
WHERE termination_date IS NULL AND a.expiration_date > p_date AND trade_date <= p_date
@@ -627,7 +623,6 @@ ORDER BY dealid, date DESC;
END
$$ LANGUAGE plpgsql;
-
CREATE OR REPLACE function list_abscds_marks(p_date date)
RETURNS TABLE(security_id varchar(12), cusip varchar(9), security_desc varchar(32), maturity date,
notional float, factor float, fixed_rate float, clean_nav float, accrued float) AS $$