aboutsummaryrefslogtreecommitdiffstats
path: root/python/parse_gs.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/parse_gs.py')
-rw-r--r--python/parse_gs.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/python/parse_gs.py b/python/parse_gs.py
new file mode 100644
index 00000000..30e04b04
--- /dev/null
+++ b/python/parse_gs.py
@@ -0,0 +1,44 @@
+import pandas as pd
+import pdb
+import re
+
+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)
+ 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)
+ 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)