diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/trade_dataclasses.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py index e885992b..2559585a 100644 --- a/python/trade_dataclasses.py +++ b/python/trade_dataclasses.py @@ -505,7 +505,8 @@ class CitcoTrade(Citco): obj["TradeDate"] = obj["TradeDate"].strftime("%Y%m%d") obj["SettlementDate"] = obj["SettlementDate"].strftime("%Y%m%d") obj["FillQty"] = obj["OrderQty"] - obj["FillPrice"] = obj["AvgPrice"] + if self._table_name not in ("cds",): + obj["FillPrice"] = obj["AvgPrice"] return obj @@ -517,7 +518,7 @@ class CDSDeal( Deal, deal_type=DealType.CDS, table_name="cds", - insert_ignore=("id", "dealid"), + insert_ignore=("id", "dealid", "factor"), ): fund: Fund = field(metadata={"mtm": "Account Abbreviation", "citco": "Fund"}) account_code: str @@ -532,7 +533,7 @@ class CDSDeal( notional: float = field(metadata={"mtm": "1st Leg Notional", "citco": "OrderQty"}) fixed_rate: float = field(metadata={"mtm": "1st Leg Rate"}) upfront: float = field(metadata={"mtm": "Initial Payment"}) - traded_level: Decimal = field(metadata={"citco": "AvgPrice"}) + traded_level: Decimal effective_date: datetime.date = field( default=None, metadata={"mtm": "Effective Date"} ) @@ -551,6 +552,8 @@ class CDSDeal( ) orig_attach: int = field(default=None, metadata={"mtm": "Attachment Point"}) orig_detach: int = field(default=None, metadata={"mtm": "Exhaustion Point"}) + attach: int = field(default=None) + detach: int = field(default=None) swap_type: SwapType = "CD_INDEX" clearing_facility: ClearingFacility = "ICE-CREDIT" isda_definition: IsdaDoc = "ISDA2014" @@ -562,12 +565,24 @@ class CDSDeal( initial_margin_percentage: float = field( default=None, metadata={"mtm": "Independent Amount (%)"} ) + factor: float = field(default=1, init=False, metadata={"insert": False}) bbg_ticket_id: str = None def __post_init__(self): start_protection = self.trade_date + datetime.timedelta(days=1) effective_date = previous_twentieth(prev_business_day(start_protection)) self.effective_date = adjust_next_business_day(effective_date) + if self.attach: + self.factor = (self.detach - self.attach) / ( + self.orig_detach - self.orig_attach + ) + else: + with self._conn() as c: + c.execute( + "SELECT index_factor / 100 from index_version where redindexcode=%s", + (self.security_id,), + ) + (self.factor,) = c.fetchone() def to_markit(self): obj = self.serialize("mtm") @@ -591,8 +606,16 @@ class CDSDeal( def to_citco(self): obj = super().to_citco() obj["SecurityType"] = "CDS" - obj["BuySellShortCover"] = "B" if obj["protection"] == "Buy" else "S" obj["SettleCurrency"] = obj["SecurityCurrency"] + obj["AvgPrice"] = ( + obj["OrderQty"] / obj["upfront"] / obj["factor"] / 100 + ) # Citco looks at factor as 1/100 + if obj["protection"] == "Buyer": + obj["BuySellShortCover"] = "S" + else: + obj["BuySellShortCover"] = "B" + obj["AvgPrice"] = -obj["AvgPrice"] + obj["FillPrice"] = obj["AvgPrice"] if obj["orig_attach"]: # tranche process obj["IDSource"] = "USERID" @@ -1787,7 +1810,6 @@ class TRSProduct( self.stage() self.commit() self.get_productid() - obj = super().to_citco() d = { f"S_P_CurrencyCode": self.currency, |
