aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql14
1 files changed, 8 insertions, 6 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index eaaa289d..c80f22d1 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -106,7 +106,7 @@ CREATE OR REPLACE function list_positions(p_date date,
RETURNS TABLE(identifier varchar(12), description varchar(32), notional float, strategy bond_strat,
curr_cpn float, start_accrued_date date, last_settle_date date,
principal_payment float, accrued_payment float, currency currency, daycount day_count,
- day_bbg_type bbg_type) AS $$
+ bbg_type bbg_type) AS $$
DECLARE sqlquery text;
DECLARE asset_opt text;
DECLARE unsettled_opt text;
@@ -226,15 +226,17 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE function risk_positions(p_date date, p_assetclass asset_class) RETURNS TABLE
(description varchar(32), identifier varchar(12), notional float, price float,
strategy bond_strat, factor float, local_market_value float, usd_market_value float,
-curr_cpn float, int_acc float) AS $$
+curr_cpn float, int_acc float, last_pay_date date, principal_payment float,
+accrued_payment float, last_settle_date date) AS $$
BEGIN
RETURN QUERY
SELECT a.description, a.identifier, a.notional, c.price, a.strategy, coalesce(b.factor, 1),
- c.price * a.notional * coalesce(b.factor,1),
- c.price * a.notional * coalesce(b.factor,1) * fxrate,
+ c.price/100. * a.notional * (CASE WHEN coalesce(b.factor,1)=0 THEN 1 ELSE coalesce(b.factor,1) END),
+ c.price/100. * a.notional * (CASE WHEN coalesce(b.factor,1)=0 THEN 1 ELSE coalesce(b.factor,1) END) * fxrate,
a.curr_cpn,
- a.notional * coalesce(b.factor,1) * fxrate *yearfrac(start_accrued_date, '2015-08-06', daycount) *
- a.curr_cpn/100.
+ a.notional * coalesce(b.factor,1) * fxrate *
+ yearfrac(start_accrued_date, p_date+1, daycount) * a.curr_cpn/100.,
+ b.date, a.principal_payment, a.accrued_payment, a.last_settle_date
FROM list_positions(p_date, p_assetclass) a
LEFT JOIN factors_history(p_date) b USING (identifier)
LEFT JOIN list_marks(p_date, True) c USING (identifier)