aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/headers.py2
-rw-r--r--python/mtm_upload.py66
2 files changed, 57 insertions, 11 deletions
diff --git a/python/headers.py b/python/headers.py
index a35a9aaa..913c77e1 100644
--- a/python/headers.py
+++ b/python/headers.py
@@ -380,7 +380,7 @@ HEADERS = {
}
MTM_HEADERS = {
- "tranche": [
+ "cds": [
"Swap ID",
"Allocation ID",
"Description",
diff --git a/python/mtm_upload.py b/python/mtm_upload.py
index 2728fb11..8ac6a6bd 100644
--- a/python/mtm_upload.py
+++ b/python/mtm_upload.py
@@ -71,6 +71,52 @@ def tranche_term_trades(conn):
return trades
+def terminations(tradeid, conn):
+ with conn.cursor() as c:
+ termination_query = (
+ """SELECT terminations.*, coalesce(cds.cp_code, swaptions.cp_code) AS orig_cp, COALESCE (cds."currency", swaptions."currency") AS currency, """
+ """COALESCE (cds."swap_type", 'SWAPTION') as swap_type FROM terminations LEFT JOIN cds USING (dealid) LEFT JOIN swaptions USING (dealid) where terminations.id = %s ORDER BY id desc;"""
+ )
+ c.execute(termination_query, (tradeid,))
+ for row in c:
+ obj = row._asdict()
+ rename_keys(
+ obj,
+ {
+ "dealid": "Swap ID",
+ "termination_cp": "Broker Id",
+ "termination_amount": "1st Leg Notional",
+ "termination_fee": "Initial Payment",
+ "termination_date": "Trade Date",
+ "fee_payment_date": "Settle Date",
+ "fund": "Account Abbreviation",
+ "termination_cp": "Broker Id",
+ "orig_cp": "Remaining Party",
+ "currency": "Currency Code",
+ },
+ )
+ if obj["Initial Payment"] >= 0:
+ obj["Transaction Code"] = "Receive"
+ else:
+ obj["Initial Payment"] = abs(obj["Initial Payment"])
+ obj["Transaction Code"] = "Pay"
+ match obj["swap_type"]:
+ case "CD_INDEX_TRANCHE":
+ obj["Product Type"] = "TRN"
+ case "SWAPTION":
+ obj["Product Type"] = "CDISW"
+ case _:
+ print("Not a valid termination")
+ obj["Trade ID"] = obj["Swap ID"] + "-" + str(obj["id"])
+ obj["Transaction Type"] = (
+ "Termination"
+ if obj["Remaining Party"] == obj["Broker Id"]
+ else "Assignment"
+ )
+ obj["Effective Date"] = obj["Trade Date"] + datetime.timedelta(days=1)
+ trades.append(obj)
+
+
def build_line(obj, asset_type):
return [obj.get(h, None) for h in MTM_HEADERS[asset_type]]
@@ -88,16 +134,16 @@ def process_upload(trades, asset_type, upload):
dest.write_bytes(buf)
-def upload_mtm_trades(trade_type, tradeid):
- _funs = {
- "swaption": (SwaptionDeal, "swaption"),
- "cds": (CDSDeal, "tranche"),
- }
- process_upload(
- (_funs[trade_type][0].from_tradeid(tradeid).to_markit(),),
- _funs[trade_type][1],
- upload=True,
- )
+def upload_mtm_trades(trade_type, tradeid, conn=None):
+ match trade_type:
+ case "swaption":
+ process_upload(
+ SwaptionDeal.from_tradeid(tradeid).to_markit(), trade_type, True
+ )
+ case "cds":
+ process_upload(CDSDeal.from_tradeid(tradeid).to_markit(), trade_type, True)
+ case "termination":
+ process_upload(terminations(tradeid, conn), trade_type, True)
if __name__ == "__main__":