diff options
Diffstat (limited to 'python/quote_parsing')
| -rw-r--r-- | python/quote_parsing/parse_emails.py | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py index a3a1bd9d..6783257a 100644 --- a/python/quote_parsing/parse_emails.py +++ b/python/quote_parsing/parse_emails.py @@ -587,6 +587,70 @@ def parse_bnp(fh, index_desc): logger.error(f"Can't parse expiry line: {line} for filename: {fh.name}") return option_stack, fwd_index +def parse_jpm(fh, index_desc): + option_stack = {} + fwd_index = [] + pat = re.compile(r"JPM CDX Options: IG [(](?P<ticker>[\w\d]*)[)] (?P<expiry>[\d]+-[\w]+-[\d]+) [*]{2} Fwd @(?P<fwd>[\d.]+), Delta @(?P<delta>[\d]+)") + expiration_dates = index_desc.pop("expiration_dates") + for line in fh: + if "**" in line: + if m := pat.match(line): + d = m.groupdict() + if index_desc["index"] == "HY": + d["fwdprice"] = d.pop("fwdspread") + expiry_month = datetime.datetime.strptime(d["expiry"], "%d-%b-%y").month + d["expiry"] = next( + d for d in expiration_dates if d.month == expiry_month + ) + fwd_index.append({**index_desc, **d}) + option_sack[d['expiry']] = parse_jpm_block( + fh, index_desk['index'], c == -1 + ) + +def parse_jpm_block(fh, index_type, skip_header=True): + if skip_header: + next(fh) + r = [] + for line in fh: + if '|' in line: + rec_strike, rec_data, pay_strike, pay_data = [item.strip() for item in line.split('|')] + + + +def parse_jpm(fh, index_desc): + option_stack = {} + fwd_index = [] + pat = pat = re.compile(r"JPM CDX Options: IG [(](?P<ticker>[\w\d]*)[)] (?P<expiry>[\d]+-[\w]+-[\d]+) [*]{2} Fwd @(?P<fwd>[\d.]+), Delta @(?P<delta>[\d]+)") + expiration_dates = index_desc.pop("expiration_dates") + line = next(fh).strip() + while True: + if "**" in line: + if m := pat.match(line): + d = m.groupdict() + expiry_month = datetime.datetime.strptime(d["expiry"], "%d-%b-%y").month + d['expiry'] = next( + d for d in expiration_dates in d.month == expiry_month + ) + fwd_index.append({**index_desc, **d}) + + try: + option_stack[expiry], line = parse_jpm_block(fh, index_desc["index"]) + except IndexError as e: + logger.debug(traceback.format_exc()) + logger.error(f"Something is wrong with file {Path(fh.name).stem}") + raise RuntimeError() + else: + logger.error("Can't parse expiry line:", line) + elif line.startswith("Payer"): + break + else: + try: + line = next(fh).strip() + except StopIteration: + break + + return option_stack, fwd_index + # subject_baml = re.compile(r"(?:Fwd:){0,2}(?:BAML )?(\D{2})(\d{1,2})\s") subject_baml = re.compile(r"(?:Fwd:){0,2}(?:BofA )?(\D{2})(\d{1,2}).*Ref[^\d]*([\d.]+)") @@ -601,6 +665,7 @@ subject_cs = re.compile( r"CS CDX (?P<index>IG|HY)(?P<series>\d{2})_?v?(?P<version>\d)? Options -\s+(?:\d{2}/\d{2}/\d{2}\s+)?Ref = (?P<ref>[\d.]+)[^\d]*" ) subject_bnp = re.compile(r"CDX OPTIONS RUN: (IG|HY)(\d{2}).*") +subject_jpm = re.compile(r"JPM CDX Options: CDX.([\w]+) (\w\d+) \d\w \S+-\S+ \[ref ([\d.]*).*") def get_current_version(index, series, d, conn): @@ -619,7 +684,7 @@ def parse_email(email: Path, date_received: datetime.date, conn): with email.open("rt") as fh: subject = fh.readline().lstrip() - for source in ["BAML", "GS", "MS", "NOM", "SG", "CITI", "CS", "BNP"]: + for source in ["BAML", "GS", "MS", "NOM", "SG", "CITI", "CS", "BNP", "JPM"]: if m := globals()[f"subject_{source.lower()}"].match(subject): version = None if source in ["CITI", "BNP"]: @@ -656,7 +721,7 @@ def parse_email(email: Path, date_received: datetime.date, conn): "series": series, "version": version, } - if source in ["GS", "MS", "NOM", "SG"]: + if source in ["GS", "MS", "NOM", "SG", "JPM"]: index_desc["ref"] = ref if source in ["BNP", "SG"]: index_desc["expiration_dates"] = list_imm_dates(quotedate) |
