diff options
| -rw-r--r-- | python/position.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/python/position.py b/python/position.py index 10931d0a..69a1b27f 100644 --- a/python/position.py +++ b/python/position.py @@ -122,13 +122,14 @@ def init_swap_rates(conn, session, tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20 def init_swaption_vol(session, tenors=['A', 'C', 'F', 'I'] + list(range(1, 11)) + [15, 20, 25, 30], source='BBIR', - vol_type='N'): + vol_type='N', + start_date=datetime.date(1990, 1, 1)): tickers = [] for t1 in tenors: for t2 in tenors[4:]: tickers.append(f"USS{vol_type}{t1:0>2}{t2} {source} Curncy") data = retrieve_data(session, tickers, ['PX_LAST'], - start_date=datetime.date(1990, 1, 1)) + start_date=start_date) return data def split_tenor_expiry(ticker, vol_type='N'): @@ -142,10 +143,8 @@ def split_tenor_expiry(ticker, vol_type='N'): return expiry, tenor def insert_swaption_vol(data, conn, source, vol_type="N"): - if source == "ICPL": - tenors = ['A', 'C', 'F'] + list(range(1, 11)) + [15, 20, 25, 30] - else: - tenors = ['A', 'C', 'F', 'I'] + list(range(1, 11)) + [15, 20, 25, 30] + tenors = ['A', 'C', 'F', 'I'] + list(range(1, 11)) + [15, 20, 25, 30] + df = pd.concat(data, axis=1) df.columns = df.columns.get_level_values(0) df.columns = pd.MultiIndex.from_tuples([split_tenor_expiry(c, vol_type) for c in df.columns]) @@ -156,7 +155,8 @@ def insert_swaption_vol(data, conn, source, vol_type="N"): 'VALUES(%s, %s, %s) ON CONFLICT (date, source)' + \ f' DO UPDATE SET "{t}y" = %s, source = %s' with conn.cursor() as c: - for k, v in df.xs(t, axis=1, level=1)[tenors].iterrows(): + df_temp = df.xs(t, axis=1, level=1).reindex(tenors, axis=1) + for k, v in df_temp.iterrows(): if np.all(np.isnan(v.values)): continue c.execute(sql_str, (k, v.tolist(), source, v.tolist(), source)) @@ -164,6 +164,8 @@ def insert_swaption_vol(data, conn, source, vol_type="N"): def update_swaption_vol(conn, session, tenors=['A', 'C', 'F', 'I'] + list(range(1, 11)) + [15, 20, 25, 30], + *, + sources=['BBIR', 'CMPN', 'ICPL'], vol_type="N"): """ Parameters @@ -187,6 +189,7 @@ def update_swaption_vol(conn, session, for expiry in tenors: ticker = f"USS{vol_type}{expiry:0>2}{t} {source} Curncy" if data[ticker]: + r.append(data[ticker]['PX_YEST_CLOSE']) dates.append(data[ticker]['PX_CLOSE_DT']) else: @@ -271,9 +274,14 @@ if __name__=="__main__": update_fx(dawn_conn, session, ['EURUSD', 'CADUSD']) update_swap_rates(serenitas_conn, session) for vol_type in ["N", "V"]: - update_swaption_vol(serenitas_conn, session, vol_type) + update_swaption_vol(serenitas_conn, session, vol_type=vol_type) # with init_bbg_session(BBG_IP) as session: # init_fx(session, engine, pd.datetime(2013, 1, 1)) - # with init_bbg_session(BBG_IP) as session: - # data = init_swaption_vol(session, source="BBIR", vol_type="V") - # insert_swaption_vol(data, serenitas_conn, "BBIR", vol_type="V") + # for source in ['BBIR', 'ICPL', 'CMPN']: + # for vol_type in ["N", "V"]: + # with init_bbg_session(BBG_IP) as session: + # data = init_swaption_vol(session, source=source, + # vol_type=vol_type, + # start_date=datetime.date(2001, 1, 1)) + # insert_swaption_vol(data, serenitas_conn, source, + # vol_type=vol_type) |
