aboutsummaryrefslogtreecommitdiffstats
path: root/python/parse_gs_exchange.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/parse_gs_exchange.py')
-rw-r--r--python/parse_gs_exchange.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/python/parse_gs_exchange.py b/python/parse_gs_exchange.py
index e80d8b1e..0d6de7c0 100644
--- a/python/parse_gs_exchange.py
+++ b/python/parse_gs_exchange.py
@@ -1,4 +1,3 @@
-from db import dbconn
from exchange import get_msgs
from pytz import timezone
from parse_emails import write_todb
@@ -7,9 +6,11 @@ import logging
import pandas as pd
import re
+
class ParseError(Exception):
pass
+
def parse_email(email, fwd_index):
m = re.search("(IG|HY)(\d{2}) 5y (?:.*)SWAPTION (?:UPDATE|CLOSES|CLOSE) - Ref\D+(.+)$",
email.subject)
@@ -18,7 +19,8 @@ def parse_email(email, fwd_index):
series = int(series)
if indextype == 'HY':
refprice, refspread = map(float,
- re.match("([\S]+)\s+\(([^)]+)\)", ref).groups())
+ re.match(r"([\S]+)\s+\(([^)]+)\)", ref).
+ groups())
else:
refspread = float(ref)
else:
@@ -51,25 +53,25 @@ def parse_email(email, fwd_index):
r.append(vals)
continue
else:
- if indextype=='HY':
+ if indextype == 'HY':
cols = ['Strike', 'Sprd', 'Pay', 'DeltaPay', 'Rec', 'Vol',
'VolChg', 'VolBpd', 'Tail']
else:
cols = ['Strike', 'Pay', 'DeltaPay', 'Rec', 'Vol',
'VolChg', 'VolBpd', 'Tail']
- df = pd.DataFrame.from_records(r, columns = cols)
+ df = pd.DataFrame.from_records(r, columns=cols)
df[['PayBid', 'PayOffer']] = df.Pay.str.split('/', expand=True)
df[['RecBid', 'RecOffer']] = df.Rec.str.split('/', expand=True)
df.drop(['Pay', 'Rec'], axis=1, inplace=True)
for col in df:
- df[col] = pd.to_numeric(df[col], errors = 'coerce')
+ df[col] = pd.to_numeric(df[col], errors='coerce')
df.set_index('Strike', inplace=True)
d = {'quotedate': quotedate,
'expiry': date,
'index': indextype,
'series': series,
- 'ref': refspread if indextype =="IG" else refprice}
+ 'ref': refspread if indextype == "IG" else refprice}
if indextype == "IG":
d['fwdspread'] = float(fwspread)
else:
@@ -80,7 +82,8 @@ def parse_email(email, fwd_index):
flag = False
r = []
continue
- return (quotedate, indextype, series, pd.concat(masterdf, names=['expiry']))
+ return quotedate, indextype, series, pd.concat(masterdf, names=['expiry'])
+
def clean_df(all_df):
all_df = pd.concat(all_df, names=['quotedate', 'index', 'series'], sort=True)
@@ -100,7 +103,8 @@ def clean_df(all_df):
del all_df['Sprd']
return all_df
-if __name__=="__main__":
+
+if __name__ == "__main__":
fwd_index = []
swaption_quotes = {}
for email in get_msgs(count=20):