aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/trade_dataclasses.py65
1 files changed, 36 insertions, 29 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py
index 7f3b1018..6b9c5900 100644
--- a/python/trade_dataclasses.py
+++ b/python/trade_dataclasses.py
@@ -1261,23 +1261,17 @@ class SwaptionProduct(
insert_ignore=(
"id",
"dealid",
- "birth_date",
- "death_date",
"security_desc",
"currency",
),
):
underlying_security_id: str = field(metadata={"citco": "UnderlyingSecurityId"})
- 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"}
)
- currency: str = field(init=False, default=None, metadata={"citco": "LocalCcy"})
+ currency: str = field(
+ init=False, default=None, metadata={"citco": "LocalCcy", "insert": False}
+ )
instrument_type: str = field(metadata={"citco": "InstrumentType"})
callput: bool
strike: float = field(metadata={"citco": "StrikePrice"})
@@ -1285,6 +1279,8 @@ class SwaptionProduct(
underlying_id_source: str = field(
default="RED", metadata={"citco": "UnderlyingIDSource"}
)
+ birth_date: datetime.date = field(default=None, metadata={"citco": "Birth_date"})
+ death_date: datetime.date = field(default=None, metadata={"citco": "Death_date"})
committed: bool = field(default=False)
id: int = field(default=None, metadata={"insert": False})
@@ -1293,7 +1289,7 @@ class SwaptionProduct(
)
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"
+ 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 and birth_date=%s and death_date=%s"
with self._conn.cursor() as c:
c.execute(
sql_str,
@@ -1303,35 +1299,48 @@ class SwaptionProduct(
self.strike,
self.expiration,
self.callput,
+ self.birth_date,
+ self.death_date,
),
)
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}"
- )
- self.currency = "EUR" if index in ("XO", "EU") else "USD"
+ self.get_dealid()
+ if self.underlying_id_source == "RED":
+ 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.security_desc = (
+ f"{desc_str(index, series, '5')} {self.expiration}-{self.strike}"
+ )
+ self.currency = "EUR" if index in ("XO", "EU") else "USD"
+ else:
+ self.security_desc = ""
def to_citco(self):
if not self.id:
self.stage()
self.commit()
self.get_dealid()
-
obj = self.serialize("citco")
+ if self.underlying_id_source == "USERID":
+ irs = IRSProduct(
+ birth_date=self.birth_date,
+ death_date=self.death_date,
+ fixed_rate=self.strike,
+ float_index=self.underlying_security_id,
+ )
+ irs.citco_stage()
+ obj["UnderlyingSecurityId"] = irs.dealid
obj["Command"] = "N"
obj["Active"] = "Y"
obj["Birth_date"] = obj["Birth_date"].strftime("%Y%m%d")
@@ -1354,12 +1363,11 @@ class IRSProduct(
Deal,
deal_type=DealType.IRSProduct,
table_name="citco_irs",
- insert_ignore=("id", "dealid"),
+ insert_ignore=("id", "dealid", "security_desc"),
):
birth_date: datetime.date = field(metadata={"citco": "Birth_date"})
death_date: datetime.date = field(metadata={"citco": "Death_date"})
fixed_rate: float
- notional: float
instrument_type: str = field(default="IRS", metadata={"citco": "InstrumentType"})
active: str = field(default=True, metadata={"citco": "Active"})
fixed_daycount: str = field(default="ACT/360")
@@ -1402,7 +1410,6 @@ class IRSProduct(
def to_citco(self):
if not self.id:
-
self.stage()
self.commit()
self.get_dealid()