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
27
28
29
30
31
32
33
34
|
import datetime
import numpy as np
import pandas as pd
from analytics.basket_index import MarkitBasketIndex
from dates import bus_day
from utils.db import serenitas_engine
ig31 = MarkitBasketIndex("IG", 31, ["5yr"])
dr = pd.bdate_range(datetime.date(2019, 1, 1), datetime.date(2019, 10, 8), freq=bus_day)
pvs = np.empty((125, len(dr)))
for i, d in enumerate(dr):
ig31.value_date = d
pv_vec = ig31.pv_vec()["2023-12-20"]
pvs[:, i] = pv_vec.protection_pv - pv_vec.duration * 0.01
# these are the clean pvs
pvs = 1 - pvs
R = np.diff(pvs) / pvs[:, :-1]
Rf = pd.DataFrame(R.T, index=dr[1:], columns=ig31.tickers)
index_price = pd.read_sql_query(
"SELECT date, closeprice, modelprice "
"from index_quotes where index='IG' "
"and series=31 and tenor='5yr' ORDER BY date",
serenitas_engine,
parse_dates=["date"],
index_col=["date"],
)
model_price = index_price.loc["2019-01-02":, "modelprice"]
rf = model_price.pct_change()
# def cost(w):
# return (Rf @ w - rf).var()
# ABX = SingleNameCds("ABX", end_date=datetime.date(2023, 12, 20), value_date=datetime.date(2019, 1, 2))
|