diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/book_bbg.py | 5 | ||||
| -rw-r--r-- | python/headers.py | 2 | ||||
| -rw-r--r-- | python/trade_dataclasses.py | 117 |
3 files changed, 123 insertions, 1 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py index fae9dd97..831592a9 100644 --- a/python/book_bbg.py +++ b/python/book_bbg.py @@ -1,5 +1,5 @@ from serenitas.utils.remote import SftpClient -from trade_dataclasses import Deal, DealType, BbgDeal +from trade_dataclasses import Deal, DealType, BbgDeal, FxswapDeal from stat import S_ISREG import re import time @@ -17,6 +17,9 @@ def run(): with sftp.client.open(f.filename) as fh: Deal[DealType(deal_type)].process(fh, bbg_id) BbgDeal._cache[bbg_id] = None + elif 'DEAL' in f.filename: + with sftp.client.open(f.filename) as fh: + FxswapDeal.process(fh, f.filename.split('_')[3]) except OSError: sftp.client.close() sftp = SftpClient.from_creds("bbg") diff --git a/python/headers.py b/python/headers.py index 904b5f3e..ad4220aa 100644 --- a/python/headers.py +++ b/python/headers.py @@ -7,6 +7,8 @@ class DealType(Enum): CDS = "CDX" Swaption = "SWAPTION" Termination = "TERM" + Spot = "SPOT" + Fxswap = "FXSWAP" HEADERS_PRE = [ 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 |
