diff options
Diffstat (limited to 'python/quote_parsing')
| -rw-r--r-- | python/quote_parsing/parse_emails.py | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/python/quote_parsing/parse_emails.py b/python/quote_parsing/parse_emails.py index 6783257a..7deb9396 100644 --- a/python/quote_parsing/parse_emails.py +++ b/python/quote_parsing/parse_emails.py @@ -590,36 +590,6 @@ def parse_bnp(fh, index_desc): 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() @@ -651,6 +621,27 @@ def parse_jpm(fh, index_desc): return option_stack, fwd_index +def parse_jpm_block(fh, indextype): + for line in fh: + line = line.strip() + if "**" in line or line == "": + break + if line.startswith("K"): + continue + rec_strike, rec_data, pay_strike, pay_data = [item.strip() for item in line.split('|')] + rec_data = rec_data.replace("/", " ") + receivers[rec_strike] = rec_data.split()[:-2] + pay_data = pay_data.replace("/", " ") + payers[pay_strike] = pay_data.split()[:-2] + + cols = ['bid', 'offer', 'delta', 'vol'] + pay = pd.DataFrame.from_dict(payers, orient='index', columns=cols).add_prefix('pay_') + rec = pd.DataFrame.from_dict(receivers, orient='index', columns=cols).add_prefix('rec_') + df = pd.concat([rec, pay], axis=1) + df['vol'] = df['rec_vol'].fillna(df['pay_vol']) + df = df.reset_index().drop(['rec_vol', "pay_vol"], axis=1).rename(columns={'index':'strike', 'pay_vol':'vol', "rec_delta": "delta_rec", "pay_delta": "delta_pay"}) + + return makedf(r, indextype, "BAML"), line # 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.]+)") |
