aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/book_bbg.py80
-rw-r--r--python/trade_dataclasses.py10
2 files changed, 42 insertions, 48 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py
index 8c6173f4..d9d139a7 100644
--- a/python/book_bbg.py
+++ b/python/book_bbg.py
@@ -58,51 +58,47 @@ def get_indic_data(conn, redcode, tenor):
def cdx_booking_process(path, conn):
- with open(path) as fh:
- reader = csv.DictReader(fh)
- for line in reader:
- tenor = line["Security"].rsplit(" ", 1)[-1].lower() + "r"
- maturity, coupon = get_indic_data(conn, tenor, line["Red Code"])
- trade = CDSDeal(
- fund=_funds[line["Account"]],
- folder="*",
- portfolio="UNALLOCATED",
- security_id=line["Red Code"],
- security_desc=line["Security"].removesuffix(" PRC"),
- traded_level=Decimal(line["Price (Dec)"]),
- notional=line["Quantity"],
- fixed_rate=coupon * 0.01,
- trade_date=datetime.datetime.strptime(
- line["Trade Dt"], "%m/%d/%Y"
- ).date(),
- maturity=maturity,
- currency=line["Curncy"],
- protection="Buyer" if line["Side"] == "B" else "Seller",
- upfront=line["Principal"],
- cp_code=_cdx_cp[line["Brkr"]],
- account_code=_fcms[line["Client FCM"]],
- )
- trade.stage()
- CDSDeal.commit()
+ reader = csv.DictReader(path)
+ for line in reader:
+ tenor = line["Security"].rsplit(" ", 1)[-1].lower() + "r"
+ maturity, coupon = get_indic_data(conn, tenor, line["Red Code"])
+ trade = CDSDeal(
+ fund=_funds[line["Account"]],
+ folder="*",
+ portfolio="UNALLOCATED",
+ security_id=line["Red Code"],
+ security_desc=line["Security"].removesuffix(" PRC"),
+ traded_level=Decimal(line["Price (Dec)"]),
+ notional=line["Quantity"],
+ fixed_rate=coupon * 0.01,
+ trade_date=datetime.datetime.strptime(line["Trade Dt"], "%m/%d/%Y").date(),
+ maturity=maturity,
+ currency=line["Curncy"],
+ protection="Buyer" if line["Side"] == "B" else "Seller",
+ upfront=line["Principal"],
+ cp_code=_cdx_cp[line["Brkr"]],
+ account_code=_fcms[line["Client FCM"]],
+ )
+ trade.stage()
+ CDSDeal.commit()
def bond_booking_process(path, fname):
- with open(path) as fh:
- reader = csv.DictReader(fh)
- for line in reader:
- line["bbg_ticket_id"] = fname
- trade = BondDeal.from_bbg_line(line)
- trade.stage()
- try:
- BondDeal.insert_bbg_line(line)
- except Exception as e:
- pass
- BondDeal._insert_queue.clear()
- print("error")
- else:
- _cache[fname] = None
- finally:
- BondDeal.commit()
+ reader = csv.DictReader(path)
+ for line in reader:
+ line["bbg_ticket_id"] = fname
+ trade = BondDeal
+ trade.stage()
+ try:
+ BondDeal.insert_bbg_line(line)
+ except Exception as e:
+ pass
+ BondDeal._insert_queue.clear()
+ print("error")
+ else:
+ _cache[fname] = None
+ finally:
+ BondDeal.commit()
def get_bbg_id(name):
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py
index ce7a519c..9d174782 100644
--- a/python/trade_dataclasses.py
+++ b/python/trade_dataclasses.py
@@ -273,9 +273,7 @@ class BondDeal(Deal, table_name="bonds"):
self.description = line["Security"].removesuffix(" Mtge")
self.buysell = line["Side"] == "B"
self.bbg_ticket_id = line["bbg_ticket_id"]
-
- def insert_bbg_line(self, line: dict):
- bond_ticket_columns = ",".join(c for c in line.keys())
- bond_place_holders = ",".join(["%s"] * len(line.keys()))
- self._bbg_sql_insert = f"INSERT INTO bond_tickets({bond_ticket_columns}) VALUES({bond_place_holders})"
- self._bbg_insert_queue.append(line.values())
+ bbg_tickets = [self.bbg_ticket_id, *line.values()]
+ place_holders = ",".join(["%s"] * len(bbg_tickets))
+ self._bbg_sql_insert = f"INSERT INTO bond_tickets VALUES({place_holders})"
+ self._bbg_insert_queue.append(bbg_tickets)