diff options
Diffstat (limited to 'python/trade_dataclasses.py')
| -rw-r--r-- | python/trade_dataclasses.py | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py index 0d36f338..0a8ce485 100644 --- a/python/trade_dataclasses.py +++ b/python/trade_dataclasses.py @@ -173,6 +173,15 @@ SwaptionStrat = Literal[ "DV01", "HEDGE_MAC", ] + +SpotStrat = Literal[ + 'M_STR_MAV', + 'M_STR_MEZZ', + 'SER_IRTXCURVE', + 'M_CSH_CASH', + 'TCSH', + "*" +] AssetClass = Literal["CSO", "Subprime", "CLO", "CRT"] @@ -290,6 +299,10 @@ class BbgDeal: cls._bbg_sql_insert = ( f"INSERT INTO cds_tickets VALUES({','.join(['%s'] * 22)})" ) + elif deal_type == DealType.Fxswap: + cls._bbg_sql_insert = ( + f"INSERT INTO fx_tickets VALUES({','.join(['%s'] * 210)})" + ) @classmethod def commit(cls): @@ -685,3 +698,107 @@ class TerminationDeal( if self.termination_cp != self.orig_cp: obj["AssignedCounterparty"] = self.termination_cp return obj + + +@dataclass +class SpotDeal( + Deal, + deal_type=DealType.Spot, + table_name="spots", + insert_ignore=("id", "dealid"), +): + folder: SpotStrat + spot_rate : float + buy_currency : str + buy_amount : float + sell_currency : str + sell_amount : float + commission_currency : str + commission : float + fund : Fund + cp_code : str + id: int = field(default=None, metadata={"insert": False}) + dealid: str = field(default=None, metadata={"insert": False}) + trade_date : datetime.date = field( + default_factory=datetime.date.today(), + ) + settle_date : datetime.date = field( + default_factory=datetime.date.today(), + ) + @classmethod + def from_bbg_line(cls, line: dict): + return cls( + folder = 'TCSH', + spot_rate = line[''] + ) + +_fx_cp = {'BAST': 'BAMSNY', 'MSST': 'MSCSNY'} +_fx_funds = {'serenitas': 'SERCGMAST', 'bowdst': 'BOWDST'} +@dataclass +class FxswapDeal( + BbgDeal, + Deal, + deal_type=DealType.Fxswap, + table_name="fx_swaps", + insert_ignore=("id", "dealid"), +): + folder: str + portfolio: str + trade_date : datetime.date + near_settle_date : datetime.date + near_buy_currency: str + near_buy_amount: float + near_sell_currency: str + near_sell_amount: float + near_rate: float + far_rate: float + far_settle_date: datetime.date + far_buy_currency: str + far_buy_amount: float + far_sell_currency: str + far_sell_amount: str + fund : Fund + cp_code : str + cash_account : str + id: int = field(default=None, metadata={"insert": False}) + dealid: str = field(default=None, metadata={"insert": False}) + @classmethod + def from_bbg_line(cls, line: dict): + if line['Side'] == 'S': + near_buy_currency = line['Currency 1'] + near_buy_amount = line['Amount Dealt'] + near_sell_currency = line['Currency 2'] + near_sell_amount = line['Counter Amount'] + far_buy_currency = line['Currency 2'] + far_buy_amount = line['Far Counter Amount'] + far_sell_currency = line['Currency 1'] + far_sell_amount = line['Far Amount Dealt'] + elif line['Side'] == 'B': + near_sell_currency = line['Currency 1'] + near_sell_amount = line['Amount Dealt'] + near_buy_currency = line['Currency 2'] + near_buy_amount = line['Counter Amount'] + far_sell_currency = line['Currency 2'] + far_sell_amount = line['Far Counter Amount'] + far_buy_currency = line['Currency 1'] + far_buy_amount = line['Far Amount Dealt'] + return cls( + folder = '*', + portfolio= 'UNALLOCATED', + cp_code = _fx_cp[line['Counterparty Deal Code']], + trade_date = datetime.datetime.strptime(line['Date Of Deal'], "%Y%m%d"), + near_settle_date = datetime.datetime.strptime(line['Value Date Period 1 Currency 1'], "%Y%m%d"), + far_settle_date = datetime.datetime.strptime(line['Value Date Period 2 Currency 1'], "%Y%m%d"), + near_buy_currency = near_buy_currency, + near_buy_amount = near_buy_amount, + near_sell_currency = near_sell_currency, + near_sell_amount = near_sell_amount, + far_buy_currency = far_buy_currency, + far_buy_amount = far_buy_amount, + far_sell_currency = far_sell_currency, + far_sell_amount = far_sell_amount, + fund = _fx_funds[line['ALOC Account 1']], + near_rate = line['Exchange Rate Period 1'], + far_rate = line['Exchange Rate Period 2'], + cash_account = 'V0NSCLMAMB', + )
\ No newline at end of file |
