aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/queries.py
blob: 1c735fa897113eea44fc4083ac1f78857283b6d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BOND_QUERY = "SELECT * FROM risk_positions(%s, null, %s) "

FUTURE_QUERY = (
    "WITH tmp AS (SELECT bbg_ticker, fund, security_desc, currency, maturity, account_code, dealid, buysell, sum(quantity * (2*buysell::int-1)) OVER (PARTITION BY bbg_ticker, fund, security_desc, currency, maturity) notional FROM futures "
    "WHERE trade_date <= %s AND fund=%s) "
    "SELECT bbg_ticker, notional, code AS cp_code, cash_account, security_desc, currency, maturity, account_code, dealid, buysell FROM tmp LEFT JOIN accounts USING (fund) WHERE tmp.notional != 0 AND account_type='Future';"
)

TRANCHE_QUERY = "SELECT trb.trade_id, trb.serenitas_clean_nav + trb.serenitas_accrued as mtm, trb.notional * trb.tranche_factor as active_notional, cds.*, index_version.redindexcode as globeop_id  FROM tranche_risk_master trb left join cds on trade_id=id LEFT JOIN index_version using (INDEX, series) WHERE date=%s AND trb.fund=%s AND lastdate= 'infinity';"

CDX_SWAPTION_QUERY = "SELECT abs(spr.notional) AS active_notional, spr.serenitas_nav, swaptions.*, index_version_markit.annexdate FROM list_swaption_positions_and_risks(%s, %s) spr LEFT JOIN swaptions  ON deal_id=dealid LEFT JOIN index_version_markit ON swaptions.security_id=redindexcode;"

IR_SWAPTION_QUERY = "SELECT abs(spr.notional) AS active_notional, spr.nav as serenitas_nav, swaptions.*, index_version_markit.effectivedate, swaptions.security_id as globeop_id FROM list_ir_swaption_positions(%s, %s) spr LEFT JOIN swaptions  ON deal_id=dealid LEFT JOIN index_version_markit ON swaptions.security_id=redindexcode;"

CDX_QUERY = "SELECT cds.*, ivm.effectivedate FROM list_cds_marks(%s, null, %s) cds LEFT JOIN index_version_markit ivm ON security_id=redindexcode;"

IRS_QUERY = "SELECT isr.pv, irs.*, accounts2.name FROM ir_swap_risk isr LEFT JOIN irs ON id=swp_id LEFT JOIN accounts2 USING (cash_account) WHERE date=%s AND irs.fund=%s;"