diff options
| -rw-r--r-- | python/parse_gs.py | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/python/parse_gs.py b/python/parse_gs.py index 30e04b04..ccb56c14 100644 --- a/python/parse_gs.py +++ b/python/parse_gs.py @@ -1,44 +1,59 @@ import pandas as pd import pdb import re +import os -with open("example") as fh: - flag = False - masterdf = {} - for line in fh: - line = line.lstrip() - if line.startswith("At"): - quotedate = pd.to_datetime(line[4:]) - if line.startswith("Expiry"): - m = re.match("Expiry (\d{2}\w{3}\d{2}) \(([^\t]+) ([^t]+)\)", line) +for f in os.listdir("quotes"): + with open(os.abspath(f)) as fh: + flag = False + masterdf = {} + for line in fh: + line = line.lstrip() + m = re.search("(IG|HY)24 5y SWAPTION UPDATE - Ref\D+(.+)$", line) if m: - date, fwprice, fwspread = m.groups() - date = pd.datetime.strptime(date, '%d%b%y') - continue - if line.startswith("Stk"): - flag = True - r = [] - continue - if flag: - if line: - vals = re.sub(" +", " ", line).split(" ") - vals.pop(2) - vals.pop(9) - r.append(vals) + indextype = m.groups()[0] + if indextype=='HY': + refprice, refspread = re.match("([^\t]+)\t+\(.*\)", m.groups()[1]).groups() + else: + refspread = m.groups()[1] continue - else: - df = pd.DataFrame.from_records(r, - columns = ['Stk', 'Sprd', 'Pay', 'Delta', 'Rec', 'Vol', - 'VolChg', 'VolBpd', 'Tail']) - df['forward'] = float(fwprice) - df['spread'] = float(fwspread) - df[['PayBid', 'PayOffer']] = df.Pay.str.split('/').apply(pd.Series) - df[['RecBid', 'RecOffer']] = df.Rec.str.split('/').apply(pd.Series) - df.drop(['Pay', 'Rec'], axis=1, inplace=True) - df = df.convert_objects(convert_numeric=True) - df.set_index('Stk', inplace=True) - masterdf[date]=df - flag = False + if line.startswith("At"): + quotedate = pd.to_datetime(line[4:]) + continue + if line.startswith("Expiry"): + m = re.match("Expiry (\d{2}\w{3}\d{2}) \(([^\t]+) ([^t]+)\)", line) + if m: + date, fwprice, fwspread = m.groups() + date = pd.datetime.strptime(date, '%d%b%y') + continue + if line.startswith("Stk"): + flag = True r = [] continue + if flag: + if line: + vals = re.sub(" +", " ", line).split(" ") + if indextype=='HY': + vals.pop(2) + vals.pop(9) + else: + vals.pop(1) + vals.pop(8) + r.append(vals) + continue + else: + df = pd.DataFrame.from_records(r, + columns = ['Stk', 'Sprd', 'Pay', 'Delta', 'Rec', 'Vol', + 'VolChg', 'VolBpd', 'Tail']) + df['forward'] = float(fwprice) + df['spread'] = float(fwspread) + df[['PayBid', 'PayOffer']] = df.Pay.str.split('/').apply(pd.Series) + df[['RecBid', 'RecOffer']] = df.Rec.str.split('/').apply(pd.Series) + df.drop(['Pay', 'Rec'], axis=1, inplace=True) + df = df.convert_objects(convert_numeric=True) + df.set_index('Stk', inplace=True) + masterdf[date]=df + flag = False + r = [] + continue masterdf = pd.concat(masterdf) |
