diff options
Diffstat (limited to 'python/markit')
| -rw-r--r-- | python/markit/import_quotes.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/python/markit/import_quotes.py b/python/markit/import_quotes.py index 39f9ee9e..de9f86bf 100644 --- a/python/markit/import_quotes.py +++ b/python/markit/import_quotes.py @@ -10,6 +10,7 @@ from dataclasses import dataclass from itertools import chain from pandas.tseries.offsets import BDay from pyisda.curve import SpreadCurve, DocClause, Seniority +from typing import Dict, List, Set, Tuple from yieldcurve import get_curve logger = logging.getLogger(__name__) @@ -57,7 +58,11 @@ class CurveKey: spread: int -def get_markit_bbg_mapping(database, basketid_list, workdate): +def get_markit_bbg_mapping( + database, basketid_list, workdate +) -> Tuple[ + Set[Tuple[str, str]], Dict[CurveKey, Set[Tuple[Tuple[str], Tuple[int, Seniority]]]] +]: markit_bbg_mapping = defaultdict(set) all_tickers = set([]) with database.cursor() as c: @@ -82,13 +87,13 @@ def get_markit_bbg_mapping(database, basketid_list, workdate): ## or same curves (not ok since date, curve_ticker needs to be unique) ## therefore we keep them in a set structure markit_bbg_mapping[key].add( - (tuple(rec.cds_curve), (rec.company_id, Seniority[rec.seniority])) + ((rec.company_id, Seniority[rec.seniority]), tuple(rec.cds_curve)) ) database.commit() return (all_tickers, markit_bbg_mapping) -def get_bbg_tickers(database, basketid_list, workdate): +def get_bbg_tickers(database, basketid_list: List[int], workdate: datetime.date): with database.cursor() as c: c.execute( "SELECT distinct cds_curve FROM historical_cds_issuers(%s) " @@ -167,7 +172,7 @@ def insert_cds(database, workdate): upfront_rates = np.array([convert(line[c]) / 100 for c in colnames]) recovery_rates = np.full(8, convert(line["RealRecovery"]) / 100) coupon_rates = coupon_100 if spread == 100 else coupon_500 - for _, bbg_id in markit_bbg_mapping[k]: + for bbg_id, _ in markit_bbg_mapping[k]: if event_date := default_table.get(bbg_id, False): if workdate >= event_date: defaulted = event_date @@ -193,7 +198,7 @@ def insert_cds(database, workdate): except ValueError: logging.error(f"couldn't build curve for {k.ticker}") buf = sc.as_buffer(True) - for curves, (cid, sen) in markit_bbg_mapping[k]: + for (cid, sen), curves in markit_bbg_mapping[k]: c.execute( "INSERT INTO cds_curves VALUES(%s, %s, %s, %s)", (workdate, cid, sen.name, buf), |
