diff options
Diffstat (limited to 'python/reallocate_iam.py')
| -rw-r--r-- | python/reallocate_iam.py | 95 |
1 files changed, 36 insertions, 59 deletions
diff --git a/python/reallocate_iam.py b/python/reallocate_iam.py index 520b4291..05070ac0 100644 --- a/python/reallocate_iam.py +++ b/python/reallocate_iam.py @@ -3,59 +3,23 @@ from serenitas.ops.funds import Service from report_ops.cash import IAMDeal from serenitas.analytics.dates import prev_business_day -_bowdst_iam_cp = { - "BAML_ISDA": "BOANNY", - "CS": "CSITLN", - "GS": "GOLINY", - "BNP": "BNPBNY", - "MS": "MSCILN", - "JPM": "JPCBNY", - "GS_FCM": "GOLDNY", -} -_serenitas_iam_cp = { - "BAML_ISDA": "BAMSNY", - "CS": "CSFBBO", - "GS": "GOLDNY", - "BNP": "BNPBNY", - "MS": "MSCSNY", - "JPM": "JPCBNY", - "GS_FCM": "GOLDNY", -} - - -def get_counterparty(fund, iam_broker): - match fund: - case "SERCGMAST": - return _serenitas_iam_cp[iam_broker] - case "BOWDST": - return _bowdst_iam_cp[iam_broker] - - -def get_custodian_account(fund, iam_broker): - match fund, iam_broker: - case ("SERCGMAST", "WF_FCM"): - return ("WELLSFCM", "WFNSCLMFCM") - case ("SERCGMAST", "BAML_FCM"): - return ("BOMLCM", "V0NSCLMFCM") - case ("BOWDST", "GS_FCM"): - return ("GS", "057363418ICE-CDS") - case ("SERCGMAST", _): - return ("UMB", "159260.1") - case ("BOWDST", _): - return ("BNY", "751254") - - -def globeop_mapping(fund, iam_broker): - (custodian, cash_account) = get_custodian_account(fund, iam_broker) - return { - "custodian": custodian, - "cash_account": cash_account, - "counterparty": get_counterparty(fund, iam_broker), - } +def gen_old_iam(fund, cob, conn): + with conn.cursor() as c: + c.execute( + "SELECT * FROM iam_tickets WHERE trade_date=%s AND fund=%s", + ( + cob, + fund, + ), + ) + for row in c: + d = row._asdict() + yield IAMDeal.from_dict(**d).to_globeop("CANCEL") + c.execute("DELETE FROM iam_tickets WHERE trade_date=%s AND fund=%s") -def gen_new_iam_deals(fund, cob, conn): +def gen_new_iam(fund, cob, conn): with conn.cursor() as c: c.execute( "SELECT * FROM list_iam(%s, %s)", @@ -65,8 +29,8 @@ def gen_new_iam_deals(fund, cob, conn): ), ) for row in c: - d = row._asdict() | globeop_mapping(fund, row.broker) - yield IAMDeal.from_dict(**d) + d = row._asdict() + yield IAMDeal.from_dict(**d).to_globeop("NEW") def gen_new_iam_offsets(fund, cob, conn): @@ -80,17 +44,29 @@ def gen_new_iam_offsets(fund, cob, conn): ), ) for row in c: - d = ( - row._asdict() - | globeop_mapping(fund, row.broker) - | {"offset": True, "folder": "M_CSH_CASH"} - ) - return IAMDeal.from_dict(**d) + d = row._asdict() | {"offset": True, "folder": "M_CSH_CASH"} + yield IAMDeal.from_dict(**d).to_globeop("NEW") + + +def gen_matured_iam(fund, cob, conn): + with conn.cursor() as c: + c.execute( + "SELECT * FROM iam_tickets WHERE maturity is NULL AND trade_date=%s AND fund=%s", + (prev_business_day(cob), fund), + ) + for row in c: + yield IAMDeal.from_dict(**d).to_globeop("UPDATE") + c.execute( + "UPDATE iam_tickets SET maturity =%s WHERE maturity is NULL AND trade_date=%s AND fund=%s", + (cob, fund), + ) def main(fund, cob, conn): service = Service[fund] - for iam in gen_iam_deals(fund, cob, conn): + for iam in gen_old_iam(fund, cob, conn): + iam.stage() + for iam in gen_iam(fund, cob, conn): iam.stage() if fund in ("BOWDST"): for iam in gen_iam_offsets(fund, cob, conn): @@ -98,6 +74,7 @@ def main(fund, cob, conn): for iam in IamDeal.commit(): service.push(iam) buf, dest = service.build_buffer() + conn.commit() if __name__ == "__main__": |
