aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/index_data.py8
-rw-r--r--python/notebooks/risk_sabo.ipynb42
2 files changed, 10 insertions, 40 deletions
diff --git a/python/analytics/index_data.py b/python/analytics/index_data.py
index 61d283e7..89c2754d 100644
--- a/python/analytics/index_data.py
+++ b/python/analytics/index_data.py
@@ -269,13 +269,15 @@ def get_singlenames_curves_prebuilt(conn, index_type, series, trade_date):
def load_all_curves(conn, trade_date):
with conn.cursor() as c:
c.execute(
- "SELECT curve, referenceentity FROM cds_curves "
+ "SELECT curve, referenceentity, company_id FROM cds_curves "
"LEFT JOIN refentity ON redcode=redentitycode WHERE date=%s",
(trade_date,),
)
- r = [(name, SpreadCurve.from_bytes(b, True)) for (b, name) in c]
+ r = [(name, SpreadCurve.from_bytes(b, True), cid) for (b, name, cid) in c]
r = pd.DataFrame.from_records(
- r, columns=["name", "curve"], index=[c.full_ticker for _, c in r]
+ r,
+ columns=["name", "curve", "company_id"],
+ index=[c.full_ticker for _, c, _ in r],
)
return r.loc[r.index.drop_duplicates()]
diff --git a/python/notebooks/risk_sabo.ipynb b/python/notebooks/risk_sabo.ipynb
index ccfea2bc..5106056c 100644
--- a/python/notebooks/risk_sabo.ipynb
+++ b/python/notebooks/risk_sabo.ipynb
@@ -3,11 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "jupyter": {
- "source_hidden": true
- }
- },
+ "metadata": {},
"outputs": [],
"source": [
"import datetime\n",
@@ -96,37 +92,7 @@
"from utils.db import serenitas_pool\n",
"conn = serenitas_pool.getconn()\n",
"surv_curves = load_all_curves(conn, spread_date)\n",
- "serenitas_pool.putconn(conn)\n",
- "surv_prob = surv_curves['curve'].apply(lambda sc: pd.Series(sc.survival_probability(jtd.columns.date), index=jtd.columns))\n",
- "surv_prob = surv_prob.loc[jtd.index]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "jtd = (1-surv_prob) * jtd\n",
- "jtd = jtd.groupby(jtd.index.str.extract(\"([^_]*)\", expand=False)).sum()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "jtd"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "ref_names = surv_curves.groupby(surv_curves.index.str.extract(\"([^_]*)\", expand=False))['name'].first()"
+ "serenitas_pool.putconn(conn)"
]
},
{
@@ -135,7 +101,9 @@
"metadata": {},
"outputs": [],
"source": [
- "ref_names[jtd.index]"
+ "jtd_sabo = jtd[[jtd.columns[0]]].join(surv_curves.groupby(level=0).first()[['name', 'company_id']])\n",
+ "jtd_sabo.columns = ['jtd', 'name', 'company_id']\n",
+ "jtd_sabo.to_csv(base_dir / f\"jtd_{position_date:%Y%m%d}.csv\")"
]
},
{