aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/process_queue.py74
1 files changed, 67 insertions, 7 deletions
diff --git a/python/process_queue.py b/python/process_queue.py
index 0a5e0c29..503af5bb 100644
--- a/python/process_queue.py
+++ b/python/process_queue.py
@@ -321,7 +321,37 @@ def rename_keys(d, mapping):
d[v] = d.pop(k)
-def build_termination(obj):
+def build_termination(
+ base_dir,
+ dawndb,
+ dealid,
+ fee,
+ termination_date=datetime.date.today(),
+ termination_amount=None,
+ termination_cp=None,
+):
+ """ if termination_amount is None, assume full termination
+ if termination_cp is None assume termination, otherwise assignment
+ """
+ with dawndb.cursor() as c:
+ c.execute(
+ "SELECT dealid, cp_code, notional FROM swaptions where id=%s", (dealid,)
+ )
+ dealid, cp_code, notional = c.fetchone()
+ c.execute(
+ "UPDATE swaptions "
+ "SET termination_amount=%s, termination_cp=%s, termination_fee=%s, "
+ "termination_date=%s "
+ "WHERE dealid=%s",
+ (
+ termination_amount or notional,
+ termination_cp or cp_code,
+ fee,
+ termination_date,
+ dealid,
+ ),
+ )
+ dawndb.commit()
headers = (
[
"DealType",
@@ -339,13 +369,43 @@ def build_termination(obj):
"ClientReference",
]
+ ["Reserved"] * 4
- + ["SpecialInstructions", "AssignedCounterparty"]
- + ["Reserved"] * 7
- + ["GoTradeId"]
- + ["Reserved"] * 8
- + ["InMoney", "FeeCurrency"]
+ + ["SpecialInstructions"]
+ )
+ if termination_cp is not None:
+ headers += ["AssignedCounterparty"]
+ else:
+ headers += ["Reserved"]
+ headers += (
+ ["Reserved"] * 7 + ["GoTradeId"] + ["Reserved"] * 8 + ["InMoney", "FeeCurrency"]
+ )
+ d = {
+ "DealType": "SwaptionDeal",
+ "DealId": dealid,
+ "Action": "Update",
+ "Client": "Serenitas",
+ "SubAction": "Termination",
+ "PartialTermination": "N" if termination_amount is None else "Y",
+ "TerminationAmount": termination_amount,
+ "TerminationDate": termination_date,
+ "FeesPaid": fee if fee < 0 else None,
+ "FeesReceived": fee if fee > 0 else None,
+ "FeeCurrency": "USD",
+ }
+ if termination_cp is not None:
+ d["AssignedCounterparty"] = termination_cp
+ buf = StringIO()
+ csvwriter = csv.DictWriter(buf, headers)
+ csvwriter.writeheader()
+ csvwriter.writerow(d)
+ timestamp = datetime.datetime.now()
+ trade_type = "SwaptionDealA" if termination_cp is not None else "SwaptionDealT"
+ file_path = (
+ base_dir
+ / str(timestamp.date())
+ / f"Serenitas.ALL.{timestamp:%Y%m%d.%H%M%S}.{trade_type}.csv"
)
- return ["SwaptionDeal", obj["dealid"], "Update", "Serenitas", "Termination"]
+ file_path.write_bytes(buf.getvalue().encode())
+ return file_path
def build_line(obj, trade_type="bond"):