aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/headers.py97
-rw-r--r--python/process_queue.py83
2 files changed, 51 insertions, 129 deletions
diff --git a/python/headers.py b/python/headers.py
index 07f24b72..852671ea 100644
--- a/python/headers.py
+++ b/python/headers.py
@@ -484,6 +484,46 @@ HEADERS = {
"Collateralized",
"TradeDateFX",
],
+ "termination": [
+ "DealType",
+ "DealId",
+ "Action",
+ "Client",
+ "SubAction",
+ "PartialTermination",
+ "TerminationAmount",
+ "TerminationDate",
+ "FeesPaid",
+ "FeesReceived",
+ "DealFunction",
+ "Reserved",
+ "ClientReference",
+ "TradeDate",
+ "EffectiveDate",
+ "FirstCouponDate",
+ "FeePaymentDate",
+ "SpecialInstructions",
+ "AssignedCounterparty",
+ "AssignmentFee",
+ "AssignedFeeTradeDate",
+ "AssignedFeeValueDate",
+ "AssignedCustodian",
+ "AssignedCashAccount",
+ "Reserved",
+ "FeeCurrency",
+ "GoTradeId",
+ "FeeComments",
+ "ZeroOutInterestCashFlows",
+ "Reserved",
+ "Reserved",
+ "Reserved",
+ "Reserved",
+ "Reserved",
+ "Reserved",
+ "Reserved",
+ "InitialMargin",
+ "InitialMarginCurrency",
+ ],
}
MTM_HEADERS = {
@@ -884,60 +924,3 @@ def get_headers(trade_type, fund):
return headers
else:
return headers
-
-
-def get_termination_headers(trade_type: str, term_type: Literal["A", "T"]):
- headers = [
- "DealType",
- "DealId",
- "Action",
- "Client",
- "SubAction",
- "PartialTermination",
- "TerminationAmount",
- "TerminationDate",
- "FeesPaid",
- "FeesReceived",
- "DealFunction",
- "Reserved",
- "ClientReference",
- ]
- if trade_type == "cds":
- headers += ["TradeDate", "EffectiveDate", "FirstCouponDate"]
- else:
- headers += ["Reserved"] * 3
- headers += ["FeePaymentDate", "SpecialInstructions"]
-
- if term_type == "A":
- headers += ["AssignedCounterparty"]
- else:
- headers += ["Reserved"]
- if trade_type == "cds" and term_type == "A":
- headers += [
- "AssignmentFee",
- "AssignedFeeTradeDate",
- "AssignedFeeValueDate",
- "AssignedCustodian",
- "AssignedCashAccount",
- "Reserved",
- "FeeCurrency",
- ]
- else:
- headers += ["Reserved"] * 7
- headers += ["GoTradeId"]
- if trade_type == "cds":
- headers += ["FeeComments", "ZeroOutInterestCashFlows"]
- else:
- headers += ["Reserved"] * 2
- headers += ["Reserved"] * 4
- if trade_type == "swaption":
- headers += ["Reserved"] * 2 + ["InMoney", "FeeCurrency"]
- elif trade_type == "cds":
- if term_type == "A":
- headers += ["Reserved"] * 3
- else:
- headers += ["AssignedDealFunction"] + ["Reserved"] * 2
- headers += ["InitialMargin", "InitialMarginCurrency"]
- if term_type == "T":
- headers += ["Reserved"] * 4 + ["CreditEventOccured"]
- return headers
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