aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration/tranche_var.py
blob: 67bdcaf2c338d0cd1efa0a0e086409b1fa5fcda9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pandas as pd
from analytics import on_the_run
from analytics.utils import bus_day
from analytics.tranche_basket import Skew

dr = pd.bdate_range("2019-01-01", "2019-11-19", freq=bus_day)
skew_dict = {}
prev_skew_dict = {}
for d in dr:
    skew_dict = {}
    for index in ("IG", "HY"):
        otr = on_the_run(index, d)
        for i in range(5):
            skew_dict[(index, otr - 2 * i)] = Skew.from_desc(
                index, otr - 2 * i, "5yr", value_date=d
            )
    for k, v in skew_dict.items():
        try:
            skew_shock[(d, index, 2 * i)] = v - prev_skew_dict[k]
        except KeyError:
            continue
    prev_skew_dict = skew_dict
    skew_dict = {}