aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/book_bbg.py3
-rw-r--r--python/trade_dataclasses.py55
2 files changed, 56 insertions, 2 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py
index 33851193..e850d260 100644
--- a/python/book_bbg.py
+++ b/python/book_bbg.py
@@ -9,7 +9,7 @@ def get_bbg_id(s):
if m := re.match("(CDX|BOND)-[^_]*_([^$]*)", s):
return m.groups()
if "DEAL" in s:
- return "FXSWAP", s.split("_")[3]
+ return "SPOT", s.split("_")[3]
def run():
@@ -22,6 +22,7 @@ def run():
deal_type, bbg_id = get_bbg_id(f.filename)
except TypeError:
continue
+ print(BbgDeal._cache)
if bbg_id not in BbgDeal._cache:
with sftp.client.open(f.filename) as fh:
Deal[DealType(deal_type)].process(fh, bbg_id)
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py
index 2b87417e..2c72683a 100644
--- a/python/trade_dataclasses.py
+++ b/python/trade_dataclasses.py
@@ -294,7 +294,7 @@ class BbgDeal:
cls._bbg_sql_insert = (
f"INSERT INTO cds_tickets VALUES({','.join(['%s'] * 22)})"
)
- elif deal_type == DealType.FxSwap:
+ elif deal_type == DealType.FxSwap or deal_type == DealType.Spot:
cls._bbg_sql_insert = (
f"INSERT INTO fx_tickets VALUES({','.join(['%s'] * 211)})"
)
@@ -796,3 +796,56 @@ class FxSwapDeal(
cash_account=_fx_accounts[line["ALOC Account 1"]],
**d,
)
+
+
+@dataclass
+class SpotDeal(
+ BbgDeal,
+ Deal,
+ deal_type=DealType.Spot,
+ table_name="spots",
+ insert_ignore=("id", "dealid"),
+):
+ folder: str
+ portfolio: str
+ trade_date: datetime.date
+ settle_date: datetime.date
+ spot_rate: float
+ buy_currency: str
+ buy_amount: float
+ sell_currency: str
+ sell_amount: float
+ fund: str
+ 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):
+ cls._bbg_insert_queue.append(list(line.values()))
+ if line["Side"] == "S":
+ key1, key2 = "sell", "buy"
+ else:
+ key1, key2 = "buy", "sell"
+
+ d = {
+ f"{key1}_currency": line["Currency 1"],
+ f"{key1}_amount": line["Amount Dealt"],
+ f"{key2}_currency": line["Currency 2"],
+ f"{key2}_amount": line["Counter Amount"],
+ }
+ cls._bbg_insert_queue.append(list(line.values()))
+ 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"),
+ settle_date=datetime.datetime.strptime(
+ line["Value Date Period 1 Currency 1"], "%Y%m%d"
+ ),
+ fund=_fx_funds[line["ALOC Account 1"]],
+ spot_rate=line["Spot Basis Rate"],
+ cash_account=_fx_accounts[line["ALOC Account 1"]],
+ **d,
+ )