aboutsummaryrefslogtreecommitdiffstats
path: root/python/position.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/position.py')
-rw-r--r--python/position.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/python/position.py b/python/position.py
index 555f7a17..12e2b6a8 100644
--- a/python/position.py
+++ b/python/position.py
@@ -1,4 +1,5 @@
from bbg_helpers import init_bbg_session, retrieve_data, BBG_IP
+import datetime
import pandas as pd
from sqlalchemy import create_engine
from pandas.tseries.offsets import BDay
@@ -100,6 +101,35 @@ def update_fx(engine, session, currencies):
c.execute(sqlstr, values)
conn.commit()
+def init_swap_rates(engine, session, tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30]):
+ securities = [f"USISDA{t:02} Index" for t in tenors]
+ data = retrieve_data(session, securities, ['PX_LAST'],
+ start_date=datetime.date(1998, 10, 7))
+ for t in tenors:
+ ticker = f"USISDA{t:02} Index"
+ sql_str = f'INSERT INTO USD_swap_fixings(fixing_date, "{t}y") ' + \
+ 'VALUES(%s, %s) ON CONFLICT (fixing_date)' + \
+ f' DO UPDATE SET "{t}y" = %s'
+ conn = engine.raw_connection()
+ with conn.cursor() as c:
+ c.executemany(sql_str,
+ [(d, r, r) for d, r in data[ticker]['PX_LAST'].items()])
+ conn.commit()
+
+def update_swap_rates(engine, session,
+ tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30]):
+ securities = [f"USISDA{t:02} Index" for t in tenors]
+ data = retrieve_data(session, securities, ['PX_LAST', 'LAST_UPDATE_DT'])
+ for t in tenors:
+ ticker = f"USISDA{t:02} Index"
+ sql_str = f'INSERT INTO USD_swap_fixings(fixing_date, "{t}y") ' + \
+ 'VALUES(%(LAST_UPDATE_DT)s, %(PX_LAST)s) ON CONFLICT (fixing_date)' + \
+ f' DO UPDATE SET "{t}y" = %(PX_LAST)s'
+ conn = engine.raw_connection()
+ with conn.cursor() as c:
+ c.execute(sql_str, data[ticker])
+ conn.commit()
+
def populate_cashflow_history(engine, session, workdate=None):
securities = get_list(engine, workdate)
conn = engine.raw_connection()
@@ -145,7 +175,8 @@ def populate_cashflow_history(engine, session, workdate=None):
if __name__=="__main__":
engine = create_engine('postgresql://dawn_user@debian/dawndb')
- if len(sys.argv)>1:
+ serenitas_engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')
+ if len(sys.argv) > 1:
workdate = pd.Timestamp(sys.argv[1])
else:
workdate = pd.datetime.today()
@@ -153,5 +184,6 @@ if __name__=="__main__":
update_securities(engine, session, workdate)
populate_cashflow_history(engine, session, workdate)
update_fx(engine, session, ['EURUSD', 'CADUSD'])
+ update_swap_rates(serenitas_engine, session)
# with init_bbg_session(BBG_IP) as session:
# init_fx(session, engine, pd.datetime(2013, 1, 1))