diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/process_queue.py | 85 |
1 files changed, 59 insertions, 26 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index 3510ca75..da002aa4 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -330,17 +330,22 @@ def build_termination( termination_date=datetime.date.today(), termination_amount=None, termination_cp=None, + deal_type="CreditDefaultSwapDeal", ): """ if termination_amount is None, assume full termination if termination_cp is None assume termination, otherwise assignment """ + if deal_type == "CreditDefaultSwapDeal": + table = "cds" + elif deal_type == "SwaptionDeal": + table = "swaptions" with dawndb.cursor() as c: c.execute( - "SELECT dealid, cp_code, notional FROM swaptions where id=%s", (dealid,) + f"SELECT dealid, cp_code, notional FROM {table} where id=%s", (dealid,) ) dealid, cp_code, notional = c.fetchone() c.execute( - "UPDATE swaptions " + f"UPDATE {table} " "SET termination_amount=%s, termination_cp=%s, termination_fee=%s, " "termination_date=%s " "WHERE dealid=%s", @@ -353,34 +358,62 @@ def build_termination( ), ) dawndb.commit() - headers = ( - [ - "DealType", - "DealId", - "Action", - "Client", - "SubAction", - "PartialTermination", - "TerminationAmount", - "TerminationDate", - "FeesPaid", - "FeesReceived", - "DealFunction", - "Reserved", - "ClientReference", - ] - + ["Reserved"] * 4 - + ["SpecialInstructions"] - ) + headers = [ + "DealType", + "DealId", + "Action", + "Client", + "SubAction", + "PartialTermination", + "TerminationAmount", + "TerminationDate", + "FeesPaid", + "FeesReceived", + "DealFunction", + "Reserved", + "ClientReference", + ] + if deal_type == "CreditDefaultSwapDeal": + headears += ["TradeDate", "EffectiveDate", "FirstCouponDate", "FeePaymentDate"] + else: + header += ["Reserved"] * 4 + headers += ["SpecialInstructions"] + if termination_cp is not None: headers += ["AssignedCounterparty"] else: headers += ["Reserved"] - headers += ( - ["Reserved"] * 7 + ["GoTradeId"] + ["Reserved"] * 8 + ["InMoney", "FeeCurrency"] - ) + if deal_type == "CreditDefaultSwapDeal" and termination_cp is not None: + headers += [ + "AssignmentFee", + "AssignedFeeTradeDate", + "AssignedFeeValueDate", + "AssignedCustodian", + "AssignedCashAccount", + "Reserved", + "FeeCurrency", + ] + else: + headers += ["Reserved"] * 7 + headers += ["GoTradeId"] + if deal_type == "CreditDefaultSwapDeal": + headers += ["FeeComments", "ZeroOutInterestCashFlows"] + else: + headers += ["Reserved"] * 2 + headers += ["Reserved"] * 4 + if deal_type == "SwaptionDeal": + headers += ["Reserved"] * 2 + ["InMoney", "FeeCurrency"] + elif deal_type == "CreditDefaultSwapDeal": + if termination_cp is None: + headers += ["Reserved"] * 3 + else: + headers += ["AssignedDealFunction"] + ["Reserved"] * 2 + headers += ["InitialMargin", "InitialMarginCurrency"] + if termination_cp is None: + headers += ["Reserved"] * 4 + ["CreditEventOccured"] + d = { - "DealType": "SwaptionDeal", + "DealType": deal_type, "DealId": dealid, "Action": "Update", "Client": "Serenitas", @@ -399,7 +432,7 @@ def build_termination( csvwriter.writeheader() csvwriter.writerow(d) timestamp = datetime.datetime.now() - trade_type = "SwaptionDealA" if termination_cp is not None else "SwaptionDealT" + trade_type = f"{deal_type}A" if termination_cp is not None else f"{deal_type}T" file_path = ( base_dir / str(timestamp.date()) |
