diff options
Diffstat (limited to 'python/process_queue.py')
| -rw-r--r-- | python/process_queue.py | 83 |
1 files changed, 11 insertions, 72 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index f30410d0..aacd9cf8 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -29,7 +29,7 @@ from pyisda.date import previous_twentieth from typing import Tuple, Union from quantlib.time.api import pydate_from_qldate, UnitedStates, Days, Date from tabulate import tabulate -from headers import get_headers, get_termination_headers +from headers import get_headers from trade_dataclasses import DealKind _client_name = {"SERCGMAST": "Serenitas", "BOWDST": "HEDGEMARK", "BRINKER": "LMCG"} @@ -133,17 +133,16 @@ def terminate_list( logging.error(e) return DealKind["termination"].mtm_upload() - for obj in terms: - if upload: - dest = get_filepath(base_dir, (trade_type, "A"), fund) - buf = StringIO() - csvwriter = csv.DictWriter(buf, get_termination_headers(trade_type, "A")) - csvwriter.writeheader() - csvwriter.writerows(obj) - buf = buf.getvalue().encode() - upload_buf(buf, dest.name, fund, trade_type) - dest.parent.mkdir(exist_ok=True) - dest.write_bytes(buf) + if upload and terms: + dest = get_filepath(base_dir, (trade_type, "A"), fund) + buf = StringIO() + csvwriter = csv.DictWriter(buf, get_headers("termination", fund)) + csvwriter.writeheader() + csvwriter.writerows(terms) + buf = buf.getvalue().encode() + upload_buf(buf, dest.name, fund, trade_type) + dest.parent.mkdir(exist_ok=True) + dest.write_bytes(buf) p.delete(key) @@ -777,66 +776,6 @@ def print_trade(trade): return tabulate((k, v) for k, v in d.items()) -def build_termination( - term_dict: dict, - conn, - *, - dealid, - termination_fee: float, - fee_payment_date: datetime.date, - termination_date=datetime.date.today(), - termination_amount=None, - termination_cp=None, - globeopid=None, - partial_termination: bool = False, - is_assignment: bool = False, - ccy: str = "USD", - fund: str = "SERCGMAST", - **kwargs, -) -> None: - """if termination_amount is None, assume full termination - if termination_cp is None assume termination, otherwise assignment - """ - if dealid.startswith("SWPTN"): - deal_type = "SwaptionDeal" - elif dealid.startswith("SCCDS"): - deal_type = "CreditDefaultSwapDeal" - else: - deal_type = "CapFloorDeal" - - if deal_type == "CreditDefaultSwapDeal": - with conn.cursor() as c: - c.execute( - "SELECT (detach-attach)/(orig_detach-orig_attach) " - "FROM cds WHERE dealid=%s", - (dealid,), - ) - (tranche_factor,) = c.fetchone() - termination_amount *= tranche_factor - - d = { - "DealType": deal_type, - "DealId": dealid if globeopid is None else None, - "GoTradeId": globeopid if globeopid else None, - "Action": "Update", - "Client": _client_name[fund], - "SubAction": "Termination", - "PartialTermination": "Y" if partial_termination else "N", - "TerminationAmount": termination_amount, - "TerminationDate": termination_date, - "FeesPaid": -termination_fee if termination_fee < 0 else None, - "FeesReceived": termination_fee if termination_fee > 0 else None, - "FeePaymentDate": fee_payment_date, - } - if deal_type == "SwaptionDeal" or ( - deal_type == "CreditDefaultSwapDeal" and is_assignment - ): - d["FeeCurrency"] = ccy - if is_assignment: - d["AssignedCounterparty"] = termination_cp - term_dict["A" if is_assignment else "T"].append(d) - - if __name__ == "__main__": import os |
