aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/process_queue.py71
1 files changed, 49 insertions, 22 deletions
diff --git a/python/process_queue.py b/python/process_queue.py
index 22c50d50..399cd3ff 100644
--- a/python/process_queue.py
+++ b/python/process_queue.py
@@ -539,30 +539,57 @@ def cds_trade_process(conn, session, trade):
else:
trade["curr_notional"] = trade["notional"] * factor
trade["Factor"] = factor
- if not is_tranche_trade(trade):
- index = CreditIndex(
- redcode=trade["security_id"],
- maturity=trade["maturity"],
- notional=trade["notional"],
- value_date=trade["trade_date"],
- )
- index.direction = trade["protection"]
- with conn.cursor() as c:
- if trade["ref"]:
- index.ref = trade["ref"]
+ index = CreditIndex(
+ redcode=trade["security_id"],
+ maturity=trade["maturity"],
+ notional=trade["notional"],
+ value_date=trade["trade_date"],
+ )
+ index.direction = trade["protection"]
+ with conn.cursor() as c:
+ if trade["traded_level"]:
+ if is_tranche_trade(trade):
+ index.ref = float(trade["traded_level"])
trade["upfront"] = -index.pv
- c.execute(
- "UPDATE cds SET upfront=%s WHERE dealid=%s",
- (trade["upfront"], trade["dealid"]),
- )
else:
- index.pv = trade["upfront"]
- trade["ref"] = index.ref
- c.execute(
- "UPDATE cds SET ref=%s WHERE dealid=%s",
- (trade["ref"], trade["dealid"]),
- )
- conn.commit()
+ accrued = index._accrued * trade["fixed_rate"]
+ if index.index_type == "HY":
+ dirty_price = float(trade["traded_level"]) + accrued
+ trade["upfront"] = (
+ -(100 - dirty_price) * index.notional * trade["Factor"] * 0.01
+ )
+ elif index.index_type == "EU":
+ if trade["orig_attach"] in (6, 12):
+ if trade["orig_attach"] == 6:
+ index.recovery = 0.0
+ index.spread = float(trade["traded_level"])
+ trade["upfront"] = (
+ -index._pv * trade["notional"] * trade["Factor"]
+ )
+ elif index.index_type == "XO":
+ if trade["orig_attach"] == 35:
+ index.spread = float(trade["traded_level"])
+ trade["upfront"] = (
+ -index._pv * trade["notional"] * trade["Factor"]
+ )
+ else:
+ dirty_protection = float(trade["traded_level"]) - accrued
+ trade["upfront"] = (
+ -dirty_protection * index.notional * trade["Factor"] * 0.01
+ )
+ c.execute(
+ "UPDATE cds SET upfront=%s WHERE dealid=%s",
+ (trade["upfront"], trade["dealid"]),
+ )
+
+ else:
+ index.pv = trade["upfront"]
+ trade["traded_level"] = index.ref
+ c.execute(
+ "UPDATE cds SET traded_level=%s WHERE dealid=%s",
+ (trade["traded_level"], trade["dealid"]),
+ )
+ conn.commit()
return trade