aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/bbg_prices.py21
1 files changed, 7 insertions, 14 deletions
diff --git a/python/bbg_prices.py b/python/bbg_prices.py
index efcfb601..d699b07b 100644
--- a/python/bbg_prices.py
+++ b/python/bbg_prices.py
@@ -1,10 +1,9 @@
from bbg_helpers import init_bbg_session, retreive_data, process_msgs
-from sqlalchemy import create_engine, MetaData, Table, bindparam
+from sqlalchemy import create_engine
import numpy as np
import pandas as pd
engine = create_engine('postgresql://et_user@debian/ET')
-metadata = MetaData(bind = engine)
session = init_bbg_session('192.168.0.14', 8194)
fields_update = ["LN_ISSUE_STATUS", "AMT_OUTSTANDING", "PX_LAST","LAST_UPDATE_DT",
@@ -25,17 +24,11 @@ df.set_index(['security'], inplace=True)
df['ID_BB_UNIQUE'] = cusips['id_bb_unique'].values
df.reset_index(inplace=True)
-bloomberg_corp_ref = Table('bloomberg_corp_ref', metadata, autoload=True)
-stmt = bloomberg_corp_ref.update().\
- where(bloomberg_corp_ref.c.id_bb_unique == bindparam('ID_BB_UNIQUE')).\
- values(defaulted = bindparam('DEFAULTED'),
- default_date = bindparam('DEFAULT_DATE'),
- called = bindparam('CALLED'),
- called_date = bindparam('CALLED_DT'),
- status = bindparam('LN_ISSUE_STATUS'))
-conn = engine.connect()
-conn.execute(stmt,df[['DEFAULTED', 'DEFAULT_DATE', 'CALLED',
- 'CALLED_DT', 'LN_ISSUE_STATUS', 'ID_BB_UNIQUE']].to_dict('records'))
+conn = engine.raw_connection()
+with conn.cursor() as c:
+ c.execute("UPDATE bloomberg_corp_ref SET defaulted = %(DEFAULTED)s, " \
+ "default_date = %(DEFAULT_DATE)s, called= %(CALLED)s, called_date = %(CALLED_DT)s, " \
+ "status = %(LN_ISSUE_STATUS)s WHERE id_bb_unique=%(ID_BB_UNIQUE)", df.to_dict('records'))
currentdata = pd.read_sql_query("SELECT id_bb_unique, pricingdate from bloomberg_corp",
engine,
@@ -49,7 +42,7 @@ df.index.names = ['ID_BB_UNIQUE', 'LAST_UPDATE_DT']
df.reset_index(inplace=True)
to_insert = df[['ID_BB_UNIQUE','LAST_UPDATE_DT','PX_LAST','LN_CURRENT_MARGIN',
- 'AMT_OUTSTANDING', 'PRICING_SOURCE']]
+ 'AMT_OUTSTANDING', 'PRICING_SOURCE']]
to_insert.columns = ['id_bb_unique', 'pricingdate', 'price', 'loan_margin',
'amount_outstanding', 'source']
to_insert.to_sql('bloomberg_corp', engine, if_exists='append', index=False)