aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/risk/indices.py20
1 files changed, 4 insertions, 16 deletions
diff --git a/python/risk/indices.py b/python/risk/indices.py
index 267e0181..022eb6b3 100644
--- a/python/risk/indices.py
+++ b/python/risk/indices.py
@@ -2,7 +2,7 @@ import datetime
import logging
import pandas as pd
from serenitas.analytics.api import Portfolio, CreditIndex
-from serenitas.analytics.index_data import on_the_run, index_returns
+from serenitas.analytics.index_data import on_the_run, hist_spreads
from math import sqrt
from psycopg import Connection
from typing import Iterable, Tuple, Union
@@ -75,21 +75,9 @@ def get_index_portfolio(
def VaR(portf: Portfolio, quantile=0.05, years: int = 5, period="monthly"):
index_types = tuple(set(t.index_type for t in portf))
- df = index_returns(
- index=index_types,
- years=years,
- end_date=portf.value_date,
- tenor=["3yr", "5yr", "7yr", "10yr"],
+ returns = hist_spreads(
+ portf.value_date, index_types, ["3yr", "5yr", "7yr", "10yr"], years
)
- df = df.reorder_levels(["date", "index", "series", "tenor"])
- returns = df.spread_return.dropna().reset_index("series")
- returns["dist_on_the_run"] = returns.groupby(["date", "index"])["series"].transform(
- lambda x: x.max() - x
- )
- del returns["series"]
- returns = returns.set_index("dist_on_the_run", append=True).unstack("tenor")
- returns.columns = returns.columns.droplevel(0)
-
portf.reset_pv()
spreads = pd.DataFrame(
@@ -149,7 +137,7 @@ def insert_index_risk(d: datetime.date, conn: Connection, fund: str = "SERCGMAST
df = pd.read_sql_query(
"SELECT * FROM list_cds_positions_by_strat(%s, %s)",
conn,
- params=(d, "SERCGMAST"),
+ params=(d, fund),
)
to_insert = []
for t in df.itertuples(index=False):