diff options
| -rw-r--r-- | python/cds_rebook.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/python/cds_rebook.py b/python/cds_rebook.py index 5f8aef7f..85f1d530 100644 --- a/python/cds_rebook.py +++ b/python/cds_rebook.py @@ -2,21 +2,22 @@ from utils.db import serenitas_pool, dbconn import datetime import pandas as pd from pandas.tseries.offsets import BDay +from psycopg2.extras import execute_values from pyisda.date import default_accrual, previous_twentieth from analytics.index import CreditIndex from copy import copy -def get_outstanding_positions(conn, trade_date, fcm): +def get_outstanding_positions(conn, trade_date, fcm, fund="SERCGMAST"): with conn.cursor() as c: c.execute( "SELECT security_id, notional, folder, nextredindexcode, currency, " "maturity, indexfactor " - "FROM list_cds_positions_by_strat_fcm(%s, %s) a " + "FROM list_cds_positions_by_strat_fcm(%s, %s, %s) a " "JOIN index_version_markit " "ON a.security_id=index_version_markit.redindexcode " - "WHERE nextredindexcode IS NOT NULL", - (trade_date, fcm), + "WHERE nextredindexcode IS NOT NULL AND nextredindexcode !='2I65BRUV0'", + (trade_date, fcm, fund), ) yield from c @@ -42,14 +43,15 @@ PORTFOLIO = { "HEDGE_MBS": "MORTGAGES", "HYINX": "TRANCHE", "SER_IGCURVE": "CURVE", + "HEDGE_CLO": "CLO", } -def rebook(conn, trade_date, company_id, seniority, fcm): +def rebook(conn, trade_date, company_id, seniority, fcm, fund="SERCGMAST"): dawndb = dbconn("dawndb") upfront_settle_date = trade_date + 3 * BDay() effective_date = trade_date + datetime.timedelta(days=1) - for r in get_outstanding_positions(dawndb, trade_date, fcm): + for r in get_outstanding_positions(dawndb, trade_date, fcm, fund): accrual_days, fee = default_adjustment(conn, company_id, seniority, r.maturity) index_new = CreditIndex( redcode=r.nextredindexcode, @@ -65,6 +67,7 @@ def rebook(conn, trade_date, company_id, seniority, fcm): ) index_new.mark() trade_new = { + "fund": fund, "action": "NEW", "portfolio": PORTFOLIO[r.folder], "folder": r.folder, @@ -93,12 +96,11 @@ def rebook(conn, trade_date, company_id, seniority, fcm): ) trade_prev["upfront"] = adj - index_new.pv trade_prev["security_id"] = r.security_id - sql_str = ( - f"INSERT INTO cds({','.join(trade_new.keys())}) " - f"VALUES({','.join(['%s'] * len(trade_new))})" - ) + sql_str = f"INSERT INTO cds({','.join(trade_new.keys())}) VALUES %s" with dawndb.cursor() as c: - c.execute(sql_str, [trade_prev.values(), trade_new.values()]) + execute_values( + c, sql_str, [tuple(trade_prev.values()), tuple(trade_new.values())] + ) dawndb.commit() dawndb.close() @@ -133,6 +135,9 @@ if __name__ == "__main__": # WLL # rebook(datetime.date(2020, 5, 7), 8240322, "Senior", "BAML") # rebook(datetime.date(2020, 5, 7), 8240322, "Senior", "WF") + # rebook(conn, datetime.date(2020, 5, 7), 8240322, "Senior", "GS", "BOWDST") # FCA rebook(conn, datetime.date(2020, 5, 14), 100337, "Senior", "BAML") + rebook(conn, datetime.date(2020, 5, 14), 100337, "Senior", "WF") + rebook(conn, datetime.date(2020, 5, 14), 100337, "Senior", "GS", "BOWDST") serenitas_pool.putconn(conn) |
