diff options
Diffstat (limited to 'python/analytics/index_data.py')
| -rw-r--r-- | python/analytics/index_data.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/python/analytics/index_data.py b/python/analytics/index_data.py index 29d50cbd..57ad45cc 100644 --- a/python/analytics/index_data.py +++ b/python/analytics/index_data.py @@ -4,7 +4,7 @@ import numpy as np from .utils import tenor_t from functools import lru_cache -from pyisda.curve import SpreadCurve, Seniority, DocClause +from pyisda.curve import SpreadCurve, Seniority, DocClause, YieldCurve from multiprocessing import Pool from yieldcurve import get_curve @@ -244,3 +244,44 @@ def get_tranche_quotes(index_type, series, tenor, date=datetime.date.today()): df = pd.DataFrame.from_records(dict(d) for d in c) serenitas_pool.putconn(conn) return df + + +def get_singlename_curve( + ticker: str, + seniority: str, + doc_clause: str, + value_date: datetime.date, + yieldcurve: YieldCurve, + source: str = "MKIT", +): + conn = serenitas_pool.getconn() + with conn.cursor() as c: + c.execute( + "SELECT * FROM cds_quotes " + "JOIN (SELECT UNNEST(cds_curve) AS curve_ticker, " + " UNNEST(ARRAY[0.5, 1., 2., 3., 4., 5., 7., 10.]::float[]) AS tenor" + " FROM bbg_issuers" + " JOIN bbg_markit_mapping USING (company_id, seniority)" + " WHERE markit_ticker=%s and seniority=%s) a " + "USING (curve_ticker) WHERE date=%s AND source=%s ORDER BY tenor", + (ticker, seniority, value_date, source), + ) + df = pd.DataFrame(c, columns=[col.name for col in c.description]) + serenitas_pool.putconn(conn) + spread_curve = 0.5 * (df.runningbid + df.runningask).values * 1e-4 + upfront_curve = 0.5 * (df.upfrontbid + df.upfrontask).values * 1e-2 + return SpreadCurve( + value_date, + yieldcurve, + None, + None, + None, + df.tenor.values, + spread_curve, + upfront_curve, + df.recovery.values, + ticker=ticker, + seniority=Seniority[seniority], + doc_clause=DocClause[doc_clause], + defaulted=None, + ) |
