diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/position_file_bowdst.py | 95 |
1 files changed, 22 insertions, 73 deletions
diff --git a/python/position_file_bowdst.py b/python/position_file_bowdst.py index 9e0ae597..f47700a2 100644 --- a/python/position_file_bowdst.py +++ b/python/position_file_bowdst.py @@ -174,7 +174,7 @@ def _otc_serialize(obj, product_type, date): "strike": "Strike", "annexdate": "EffectiveDate", "expiration_date": "Underlying Maturity", - "serenitas_nav": "MTM Valuation", + "nav": "MTM Valuation", }, ) data = { @@ -190,19 +190,37 @@ def _otc_serialize(obj, product_type, date): obj["TransactionIndicator (Buy/Sell)"] = ( "B" if obj["protection"] == "Buyer" else "S" ) - elif product_type == "Swaption": - obj["Product Type"] = "CD Swaption" + elif product_type in ("CDXSwaption", "IRSwaption"): + obj["Product Type"] = ( + "CD Swaption" if product_type == "CDXSwaption" else "Swaption" + ) obj["TransactionIndicator (Buy/Sell)"] = "B" if obj["buysell"] else "S" obj["PutCall Indicator (Call/Put)"] = ( "P" if obj["option_type"] == "PAYER" else "C" ) obj["Exercise Type"] = "European" + elif product_type == "CDX": + obj["Product Type"] = "Credit Index" + obj["Counterparty"] = "GS" + obj["Unique Deal ID"] = obj[ + "Underlying (ISIN / CUSP / RED CODES)" + ] # Different from rest, we will override + obj["TransactionIndicator (Buy/Sell)"] = "B" if obj["notional"] > 0 else "S" + obj["DealCurrencyA"] = "EUR" if obj["index"] in ("EU", "XO") else "USD" + obj["NotionalA"] = abs(obj["notional"]) * obj["factor"] + obj["Start Date"] = date + obj["MTM Valuation"] = obj["clean_nav"] + obj["accrued"] + obj["Clearing House Name"] = "ICE" + obj["FixedRate"] = obj["coupon"] * 100 + obj["Effective Date"] = obj["effectivedate"] return obj _otc_queries = { "Tranche": "SELECT trb.trade_id, trb.serenitas_clean_nav + trb.serenitas_accrued as mtm, trb.notional * trb.tranche_factor as active_notional, cds.* FROM tranche_risk_bowdst trb left join cds on trade_id=id WHERE date=%s", - "Swaption": "SELECT abs(spr.notional) AS active_notional, spr.serenitas_nav, swaptions.*, index_version_markit.annexdate FROM list_swaption_positions_and_risks(%s, 'BOWDST') spr LEFT JOIN swaptions ON deal_id=dealid LEFT JOIN index_version_markit ON swaptions.security_id=redindexcode;", + "CDXSwaption": "SELECT abs(spr.notional) AS active_notional, spr.serenitas_nav as nav, swaptions.*, index_version_markit.annexdate FROM list_swaption_positions_and_risks(%s, 'BOWDST') spr LEFT JOIN swaptions ON deal_id=dealid LEFT JOIN index_version_markit ON swaptions.security_id=redindexcode;", + "IRSwaption": "SELECT abs(spr.notional) AS active_notional, spr.nav, swaptions.*, index_version_markit.effectivedate FROM list_ir_swaption_positions(%s, 'BOWDST') spr LEFT JOIN swaptions ON deal_id=dealid LEFT JOIN index_version_markit ON swaptions.security_id=redindexcode;", + "CDX": "SELECT cds.*, ivm.effectivedate FROM list_cds_marks(%s, null, 'BOWDST') cds LEFT JOIN index_version_markit ivm ON security_id=redindexcode;", } @@ -212,75 +230,6 @@ def positions_otc(conn, date): c.execute(sql_query, (date,)) yield from [_otc_serialize(row._asdict(), product_type, date) for row in c] - c.execute( - "SELECT abs(spr.notional) AS active_notional, spr.nav, swaptions.*, index_version_markit.effectivedate FROM list_ir_swaption_positions(%s, 'BOWDST') spr LEFT JOIN swaptions ON deal_id=dealid LEFT JOIN index_version_markit ON swaptions.security_id=redindexcode;", - (date,), - ) - for row in c: - obj = row._asdict() - obj["Client Name"] = "HEDGEMARK" - obj["Fund Name"] = "BOS_PAT_BOWDOIN" - obj["Product Type"] = "Swaption" - obj["TransactionIndicator (Buy/Sell)"] = "B" if obj["buysell"] else "S" - obj["PutCall Indicator (Call/Put)"] = ( - "P" if obj["option_type"] == "PAYER" else "C" - ) - obj["Exercise Type"] = "European" - obj["MTM Currency"] = "USD" - obj["COB Date"] = date - - rename_keys( - obj, - { - "dealid": "Unique Deal ID", - "cp_code": "Counterparty", - "currency": "DealCurrencyA", - "active_notional": "NotionalA", - "fixed_rate": "FixedRate", - "strike": "Strike", - "effectivedate": "Effective Date", - "trade_date": "Start Date", - "maturity": "Maturity Date", - "expiration_date": "Underlying Maturity", - "security_id": "Underlying (ISIN / CUSP / RED CODES)", - "security_desc": "Underlying Desc", - "nav": "MTM Valuation", - }, - ) - yield obj - - c.execute( - "SELECT cds.*, ivm.effectivedate FROM list_cds_marks(%s, null, 'BOWDST') cds LEFT JOIN index_version_markit ivm ON security_id=redindexcode;", - (date,), - ) - for row in c: - obj = row._asdict() - obj["Client Name"] = "HEDGEMARK" - obj["Fund Name"] = "BOS_PAT_BOWDOIN" - obj["Counterparty"] = "GS" - obj["Product Type"] = "Credit Index" - obj["Unique Deal ID"] = obj["security_id"] - obj["TransactionIndicator (Buy/Sell)"] = "B" if obj["notional"] > 0 else "S" - obj["DealCurrencyA"] = "EUR" if obj["index"] in ("EU", "XO") else "USD" - obj["NotionalA"] = abs(obj["notional"]) * obj["factor"] - obj["Start Date"] = date - obj["MTM Currency"] = "USD" - obj["MTM Valuation"] = obj["clean_nav"] + obj["accrued"] - obj["COB Date"] = date - obj["Clearing House Name"] = "ICE" - obj["FixedRate"] = obj["coupon"] * 100 - rename_keys( - obj, - { - "effectivedate": "Effective Date", - "maturity": "Maturity Date", - "security_id": "Underlying (ISIN / CUSP / RED CODES)", - "security_desc": "Underlying Desc", - }, - ) - - yield obj - if __name__ == "__main__": import argparse |
