aboutsummaryrefslogtreecommitdiffstats
path: root/python/trade_dataclasses.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/trade_dataclasses.py')
-rw-r--r--python/trade_dataclasses.py101
1 files changed, 88 insertions, 13 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py
index 9a875478..61605bf2 100644
--- a/python/trade_dataclasses.py
+++ b/python/trade_dataclasses.py
@@ -1047,7 +1047,6 @@ class TRSDeal(
@dataclass
class IRSDeal(
- # MTMDeal,
Deal,
deal_type=DealType.IRS,
table_name="irs",
@@ -1145,7 +1144,14 @@ class TrancheProduct(
Deal,
deal_type=DealType.TrancheProduct,
table_name="citco_tranche",
- insert_ignore=("id", "dealid", "birth_date", "death_date"),
+ insert_ignore=(
+ "id",
+ "dealid",
+ "birth_date",
+ "death_date",
+ "security_desc",
+ "coupon",
+ ),
):
underlying_security_id: str = field(metadata={"citco": "Underlying Security Id"})
attach: float
@@ -1172,12 +1178,12 @@ class TrancheProduct(
default=None, metadata={"insert": False, "citco": "Unique Identifier"}
)
- def get_dealid(self, underlying_id, attach, detach, conn):
+ def get_dealid(self):
sql_str = "SELECT id, dealid, committed from citco_tranche where underlying_security_id = %s and attach = %s and detach = %s"
- with conn.cursor() as c:
- c.execute(sql_str, (underlying_id, attach, detach))
+ with self._conn.cursor() as c:
+ c.execute(sql_str, (self.underlying_security_id, self.attach, self.detach))
if results := c.fetchone():
- return results.id, results.dealid, results.committed
+ (self.id, self.dealid, self.committed) = results
def __post_init__(self):
sql_str = "SELECT issue_date, maturity, coupon, index, series FROM index_version LEFT JOIN index_Maturity USING (series, INDEX) WHERE tenor='5yr' AND redindexcode=%s;"
@@ -1190,11 +1196,7 @@ class TrancheProduct(
index,
series,
) = c.fetchone()
- if results := self.get_dealid(
- self.underlying_security_id, self.attach, self.detach, self._conn
- ):
- (self.id, self.dealid, self.committed) = results
-
+ self.get_dealid()
self.security_desc = (
f"{desc_str(index, series, '5')} {self.attach}-{self.detach}"
)
@@ -1203,10 +1205,83 @@ class TrancheProduct(
if not self.id:
self.stage()
self.commit()
- (self.id, self.dealid, self.committed) = self.get_dealid(
- self.underlying_security_id, self.attach, self.detach, self._conn
+ self.get_dealid()
+ obj = self.serialize("citco")
+ obj["Command"] = "N"
+ obj["Coupon Rate"] = obj["Coupon Rate"] / 100
+ return obj
+
+
+@dataclass
+class SwaptionProduct(
+ Deal,
+ deal_type=DealType.SwaptionProduct,
+ table_name="citco_swaption",
+ insert_ignore=("id", "dealid", "birth_date", "death_date", "security_desc"),
+):
+ underlying_security_id: str = field(metadata={"citco": "Underlying Security Id"})
+ birth_date: datetime.date = field(
+ init=False, metadata={"insert": False, "citco": "Birth_date"}
+ )
+ death_date: datetime.date = field(
+ init=False, metadata={"insert": False, "citco": "Death_date"}
+ )
+ security_desc: str = field(
+ init=False, metadata={"insert": False, "citco": "Sec_Desc"}
+ )
+ instrument_type: str = field(metadata={"citco": "Instrument Type"})
+ callput: bool
+ strike: float = field(metadata={"citco": "Strike Price"})
+ expiration: datetime.date = field(metadata={"citco": "Expiration Date"})
+ underlying_id_source: str = field(
+ default="RED", metadata={"citco": "Underlying ID Source"}
+ )
+
+ committed: bool = field(default=False)
+ id: int = field(default=None, metadata={"insert": False})
+ dealid: str = field(
+ default=None, metadata={"insert": False, "citco": "Unique Identifier"}
+ )
+
+ def get_dealid(self):
+ sql_str = "SELECT id, dealid, committed from citco_swaption where instrument_type=%s and underlying_security_id =%s and strike =%s and expiration=%s and callput=%s"
+ with self._conn.cursor() as c:
+ c.execute(
+ sql_str,
+ (
+ self.instrument_type,
+ self.underlying_security_id,
+ self.strike,
+ self.expiration,
+ self.callput,
+ ),
)
+ if results := c.fetchone():
+ (self.id, self.dealid, self.committed) = results
+
+ def __post_init__(self):
+ sql_str = "SELECT issue_date, maturity, coupon, index, series FROM index_version LEFT JOIN index_Maturity USING (series, INDEX) WHERE tenor='5yr' AND redindexcode=%s;"
+ with self._conn.cursor() as c:
+ c.execute(sql_str, (self.underlying_security_id.removesuffix("_5"),))
+ (
+ self.birth_date,
+ self.death_date,
+ self.coupon,
+ index,
+ series,
+ ) = c.fetchone()
+ self.get_dealid()
+ self.security_desc = (
+ f"{desc_str(index, series, '5')} {self.expiration}-{self.strike}"
+ )
+
+ def to_citco(self):
+ if not self.id:
+ self.stage()
+ self.commit()
+ self.get_dealid()
obj = self.serialize("citco")
obj["Command"] = "N"
obj["Coupon Rate"] = obj["Coupon Rate"] / 100
+ return obj