diff options
Diffstat (limited to 'python/quote_parsing/parse_emails.py')
| -rw-r--r-- | python/quote_parsing/parse_emails.py | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py index 4dca21ff..f42dc9f5 100644 --- a/python/quote_parsing/parse_emails.py +++ b/python/quote_parsing/parse_emails.py @@ -538,6 +538,25 @@ def parse_jpm_block(fh, indextype): return makedf(df, indextype, "JPM"), line +def parse_barc_block(fh, indextype): + next(fh) # Skip headers + r = [] + for line in fh: + line = line.strip() + if line == "": + break + option_data, pay_data, delta, rec_data, vol_data = [ + item.strip() for item in line.split("|") + ] + strike, _ = option_data.split(" ") + vol = vol_data.split(" ")[0] + vals = [strike, *rec_data.split("/"), None, *pay_data.split("/"), delta, vol] + if indextype == "HY": + vals += [None] + r.append(vals) + return makedf(r, indextype, "BARC"), line + + def parse_ms(fh, index_desc, *args): option_stack = {} fwd_index = [] @@ -841,7 +860,37 @@ def parse_gs_eu(fh, index_desc): return option_stack, fwd_index -# subject_baml = re.compile(r"(?:Fwd:){0,2}(?:BAML )?(\D{2})(\d{1,2})\s") +def parse_barc(fh, index_desc): + option_stack = {} + fwd_index = [] + regex = r"(?P<expiry>\d{1,2}[A-Za-z]{3}\d{2}) \(Fwd\s+(?P<fwdprice>\d+\.\d+)" + pat = re.compile(regex) + line = next(fh).strip() + while True: + if "00Jan00" in line: + break + elif "(" in line: + if m := pat.match(line): + d = m.groupdict() + d["expiry"] = pd.to_datetime(d["expiry"], format="%d%b%y") + fwd_index.append({**index_desc, **d}) + ( + option_stack[ + (d["expiry"], index_desc["series"], index_desc["version"]) + ], + line, + ) = parse_barc_block(fh, index_desc["index"]) + else: + logger.error( + "Can't parse expiry line: %s for filename: %s", line, fh.name + ) + else: + try: + line = next(fh).strip() + except StopIteration: + break + return option_stack, fwd_index + regex_dict = { re.compile(r"(?:Fwd:){0,2}(?:BofA |BAML )?(\D{2})(\d{1,2}).*Ref[^\d]*([\d.]+)"): ( @@ -881,6 +930,10 @@ regex_dict = { re.compile( r"GS Options - iTraxx (Xover|Main|FinSen)(\d+) 5Y V(\d+) Options Run - Ref ([\d.]+)" ): ("GS", parse_gs_eu), + re.compile(r"Barclays Options CDX\.(IG|HY)(\d+) - Ref: ([\d.]+)"): ( + "BARC", + parse_barc, + ), } @@ -942,7 +995,7 @@ def parse_email(email: Path, date_received: datetime.date, conn): "series": series, "version": version, } - if source in ["GS", "MS", "NOM", "SG", "BAML"]: + if source in ["GS", "MS", "NOM", "SG", "BAML", "BARC"]: index_desc["ref"] = ref if source in ["BNP", "SG"]: index_desc["expiration_dates"] = list_imm_dates(quotedate) |
