aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/option.py3
-rw-r--r--python/cds_rebook.py48
-rw-r--r--python/notebooks/swaption_risk.ipynb9
3 files changed, 35 insertions, 25 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py
index ff22f018..b66dc1ca 100644
--- a/python/analytics/option.py
+++ b/python/analytics/option.py
@@ -135,6 +135,9 @@ class BlackSwaption(ForwardIndex):
ind.mark(ref=kwargs.pop("ref"))
else:
ind.mark()
+ if self._trade_id == 116:
+ self.sigma = 0.4
+ return
if kwargs.pop("use_external", False):
try:
self.pv = get_external_nav(dawn_engine, self._trade_id, self.value_date)
diff --git a/python/cds_rebook.py b/python/cds_rebook.py
index 8614540d..fa72bf5a 100644
--- a/python/cds_rebook.py
+++ b/python/cds_rebook.py
@@ -11,8 +11,8 @@ from copy import copy
def get_outstanding_positions(conn, trade_date, fcm, fund="SERCGMAST"):
with conn.cursor() as c:
c.execute(
- "SELECT security_id, notional, folder, b.redindexcode, currency, "
- "maturity, c.indexfactor "
+ "SELECT security_id, notional, folder, b.redindexcode, currency, "
+ "maturity, b.indexfactor "
"FROM list_cds_positions_by_strat_fcm(%s, %s, %s) a "
"LEFT JOIN index_version_markit b "
"ON a.security_id=b.prevredindexcode "
@@ -25,7 +25,7 @@ def get_outstanding_positions(conn, trade_date, fcm, fund="SERCGMAST"):
def indices_to_remark(conn, auction_date: datetime.date, fee, accrual_days):
- adj_recovery = 1 - fee + accrual_days * 0.05 / 360
+ adj_recovery = 1 - fee + (accrual_days - cds_accrued(auction_date)) * 0.05 / 360
breakpoint()
with conn.cursor() as c1, conn.cursor() as c2:
c1.execute(
@@ -88,21 +88,21 @@ def rebook(conn, trade_date, company_id, seniority, fcm, fund="SERCGMAST"):
effective_date = trade_date + datetime.timedelta(days=1)
for r in get_outstanding_positions(dawndb, trade_date, fcm, fund):
accrual_days, fee = default_adjustment(conn, company_id, seniority, r.maturity)
- index_new = CreditIndex(
- redcode=r.redindexcode,
+ index_old = CreditIndex(
+ redcode=r.security_id,
maturity=r.maturity,
value_date=trade_date,
- notional=r.notional,
+ notional=-r.notional,
freeze_version=True,
)
adj = (
- (fee - accrual_days * index_new.fixed_rate * 1e-4 / 360)
+ (fee - accrual_days * index_old.fixed_rate * 1e-4 / 360)
* r.notional
- * (r.indexfactor - index_new.factor)
+ * (r.indexfactor - index_old.factor)
)
- index_new.mark()
- trade_new = {
+ index_old.mark()
+ trade_old = {
"fund": fund,
"action": "NEW",
"portfolio": PORTFOLIO[r.folder],
@@ -115,27 +115,27 @@ def rebook(conn, trade_date, company_id, seniority, fcm, fund="SERCGMAST"):
"currency": r.currency,
"payment_rolldate": "Following",
"notional": abs(r.notional),
- "fixed_rate": index_new.fixed_rate / 100,
+ "fixed_rate": index_old.fixed_rate / 100,
"day_count": "ACT/360",
"frequency": 4,
- "protection": index_new.direction,
- "security_id": r.redindexcode,
- "security_desc": f"CDX {index_new.index_type} CDSI S{index_new.series} 5Y",
- "upfront": index_new.pv,
+ "protection": index_old.direction,
+ "security_id": r.security_id,
+ "security_desc": f"CDX {index_old.index_type} CDSI S{index_old.series} 5Y",
+ "upfront": index_old.pv,
"upfront_settle_date": upfront_settle_date,
"swap_type": "CD_INDEX",
"account_code": fcm,
}
- trade_prev = copy(trade_new)
- trade_prev["protection"] = (
- "Seller" if trade_new["protection"] == "Buyer" else "Buyer"
+ trade_new = copy(trade_old)
+ trade_new["protection"] = (
+ "Seller" if trade_old["protection"] == "Buyer" else "Buyer"
)
- trade_prev["upfront"] = adj - index_new.pv
- trade_prev["security_id"] = r.security_id
+ trade_new["upfront"] = -adj - index_old.pv
+ trade_new["security_id"] = r.redindexcode
sql_str = f"INSERT INTO cds({','.join(trade_new.keys())}) VALUES %s"
with dawndb.cursor() as c:
execute_values(
- c, sql_str, [tuple(trade_prev.values()), tuple(trade_new.values())]
+ c, sql_str, [tuple(trade_old.values()), tuple(trade_new.values())]
)
dawndb.commit()
dawndb.close()
@@ -185,7 +185,7 @@ if __name__ == "__main__":
# rebook(conn, datetime.date(2020, 5, 29), 101056, "Senior", "WF")
# rebook(conn, datetime.date(2020, 5, 29), 101056, "Senior", "GS", "BOWDST")
# JCP
- rebook(conn, datetime.date(2020, 6, 9), 101154, "Senior", "BAML")
- rebook(conn, datetime.date(2020, 5, 9), 101154, "Senior", "WF")
- rebook(conn, datetime.date(2020, 5, 9), 101154, "Senior", "GS", "BOWDST")
+ # rebook(conn, datetime.date(2020, 6, 9), 101154, "Senior", "BAML")
+ rebook(conn, datetime.date(2020, 6, 9), 101154, "Senior", "WF")
+ rebook(conn, datetime.date(2020, 6, 9), 101154, "Senior", "GS", "BOWDST")
serenitas_pool.putconn(conn)
diff --git a/python/notebooks/swaption_risk.ipynb b/python/notebooks/swaption_risk.ipynb
index babc23d2..ac08aa53 100644
--- a/python/notebooks/swaption_risk.ipynb
+++ b/python/notebooks/swaption_risk.ipynb
@@ -86,6 +86,13 @@
"execution_count": null,
"metadata": {},
"outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"portf.theta"
]
@@ -172,7 +179,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.2"
+ "version": "3.8.3"
}
},
"nbformat": 4,