aboutsummaryrefslogtreecommitdiffstats
path: root/python/calibrate_swaption.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/calibrate_swaption.py')
-rw-r--r--python/calibrate_swaption.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/python/calibrate_swaption.py b/python/calibrate_swaption.py
index d10236f7..63a44213 100644
--- a/python/calibrate_swaption.py
+++ b/python/calibrate_swaption.py
@@ -12,7 +12,7 @@ serenitas_engine = dbengine('serenitasdb')
def get_data(index, series, date=datetime.date.min):
df = pd.read_sql_query("SELECT * from swaption_ref_quotes JOIN swaption_quotes " \
- "USING (quotedate, index, series, expiry) WHERE index=%s and series=%s " \
+ "USING (ref_id) WHERE index=%s and series=%s " \
"and quotedate >=%s ORDER BY quotedate",
serenitas_engine,
params=(index, series, date), parse_dates=['quotedate', 'expiry'])
@@ -22,11 +22,11 @@ def get_data(index, series, date=datetime.date.min):
return df
def get_data_latest():
- df = pd.read_sql_query("SELECT swaption_quotes.*, ref FROM swaption_quotes " \
- "JOIN swaption_ref_quotes USING (quotedate, index, series, expiry) " \
- "LEFT JOIN swaption_calib " \
- "USING (quotedate, index, series, expiry, strike) " \
- "WHERE swaption_calib.quotedate is NULL",
+ df = pd.read_sql_query("SELECT quotedate, index, series, expiry, ref, quote_source, "
+ "swaption_quotes.* FROM swaption_ref_quotes " \
+ "JOIN swaption_quotes USING (ref_id) " \
+ "LEFT JOIN swaption_calib USING (quote_id) " \
+ "WHERE swaption_calib.quote_id is NULL",
serenitas_engine,
parse_dates=['quotedate', 'expiry'])
df.loc[(df.quote_source == "GS") & (df['index'] == "HY"),
@@ -53,7 +53,7 @@ def calib(option, ref, strike, pay_bid, pay_offer, rec_bid, rec_offer):
print(e)
else:
r.append(option.sigma)
- return [strike] + r
+ return r
@contextmanager
def MaybePool(nproc):
@@ -61,7 +61,7 @@ def MaybePool(nproc):
def calibrate(index_type=None, series=None, date=None, nproc=4, latest=False):
sql_str = ("INSERT INTO swaption_calib VALUES({}) ON CONFLICT DO NOTHING".
- format(",".join(["%s"] * 9)))
+ format(",".join(["%s"] * 5)))
if latest:
data = get_data_latest()
else:
@@ -78,7 +78,7 @@ def calibrate(index_type=None, series=None, date=None, nproc=4, latest=False):
r = pstarmap(mycalib, df[['ref', 'strike', 'pay_bid',
'pay_offer', 'rec_bid', 'rec_offer']].
itertuples(index=False, name=None))
- to_insert = [[a, index_type, series, expiry] + b for a, b in zip(df.quotedate.tolist(), r)]
+ to_insert = [[a] + b for a, b in zip(df.quote_id, r)]
serenitas_engine.execute(sql_str, to_insert)
if __name__ == "__main__":