aboutsummaryrefslogtreecommitdiffstats
path: root/python/build_default_table.py
blob: 7a91ca839cddb921bd6e8639384a5bd8aff198aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pandas as pd
from bbg_helpers import init_bbg_session, retrieve_data
from utils.db import serenitas_engine

indices = [
    "CDX HY CDSI S19 5Y",
    "ITRX XOVER CDSI S25 5Y",
    "CDX HY CDSI S15 5Y",
    "ITRX XOVER CDSI S20 5Y",
    "CDX HY CDSI S25 5Y",
    "ITRX EUR CDSI S17 10Y",
]
with init_bbg_session() as session:
    d = retrieve_data(
        session, [f"{i} Corp" for i in indices], "CDS_INDEX_DEFAULT_INFORMATION"
    )

df = pd.concat(
    [v["CDS_INDEX_DEFAULT_INFORMATION"] for v in d.values()], ignore_index=True
)
df["Company ID"] = df["Company ID"].astype("int")
df = df[~df.duplicated(["Company ID"])]
breakpoint()
df = df[["Company ID", "Auction Date", "Event Date", "CDS Recovery Rate"]]
df.columns = ["id", "auction_date", "event_date", "recovery"]
df.to_sql("defaulted", serenitas_engine, if_exists="append", index=False)