aboutsummaryrefslogtreecommitdiffstats
path: root/python/book_bbg.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/book_bbg.py')
-rw-r--r--python/book_bbg.py80
1 files changed, 38 insertions, 42 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):