aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/bbg_newids.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/python/bbg_newids.py b/python/bbg_newids.py
index 241e57a8..e5e1bd16 100644
--- a/python/bbg_newids.py
+++ b/python/bbg_newids.py
@@ -1,10 +1,8 @@
from sqlalchemy import create_engine, MetaData, select, Column, func, bindparam
from collections import defaultdict
import pandas as pd
-from db import conn
import numpy as np
-from bbg_helpers import init_bbg_session, retreive_data, process_msgs
-from psycopg2 import IntegrityError
+from bbg_helpers import init_bbg_session, retrieve_data, BBG_IP
engine = create_engine('postgresql://et_user@debian/ET')
meta = MetaData(bind=engine)
@@ -31,7 +29,7 @@ def f(s):
if s:
return "{%s}" % ",".join(s)
else:
- return ""
+ return None
clean_mapping = {cusip: f(loanxid) for cusip, loanxid in clean_mapping}
mapping = pd.DataFrame.from_dict(clean_mapping, orient='index')
@@ -41,20 +39,18 @@ currentdata = pd.read_sql_query("select id_bb_unique, cusip from bloomberg_corp_
engine, index_col='cusip')
mapping = mapping.ix[mapping.index.difference(currentdata.index)]
-session = init_bbg_session('192.168.1.108', 8194)
-all_fields = ["ISSUE_DT", "LN_ISSUE_STATUS", "ID_CUSIP", "ID_BB_UNIQUE",
- "SECURITY_TYP", "AMT_OUTSTANDING", "PX_LAST","LAST_UPDATE_DT",
- "ISSUER", "MATURITY","CPN","CPN_TYP", "CPN_FREQ","FLT_SPREAD",
- "LIBOR_FLOOR","LN_CURRENT_MARGIN", "LN_TRANCHE_SIZE", "AMT_ISSUED",
- "LN_COVENANT_LITE","SECOND_LIEN_INDICATOR","DEFAULTED", "DEFAULT_DATE",
- "CALLED", "CALLED_DT", "PRICING_SOURCE"]
-
-securities = ["{0} Corp".format(cusip) for cusip in mapping.index]
-data = retreive_data(session, securities, all_fields)
-df = process_msgs(data, all_fields)
-df.security = df.security.str.slice(0,9)
-df.set_index('security', inplace=True)
-df.reset_index(inplace=True)
+with init_bbg_session(BBG_IP) as session:
+ all_fields = ["ISSUE_DT", "LN_ISSUE_STATUS", "ID_CUSIP", "ID_BB_UNIQUE",
+ "SECURITY_TYP", "AMT_OUTSTANDING", "PX_LAST","LAST_UPDATE_DT",
+ "ISSUER", "MATURITY","CPN","CPN_TYP", "CPN_FREQ","FLT_SPREAD",
+ "LIBOR_FLOOR","LN_CURRENT_MARGIN", "LN_TRANCHE_SIZE", "AMT_ISSUED",
+ "LN_COVENANT_LITE","SECOND_LIEN_INDICATOR","DEFAULTED", "DEFAULT_DATE",
+ "CALLED", "CALLED_DT", "PRICING_SOURCE"]
+ securities = ["{0} Corp".format(cusip) for cusip in mapping.index]
+ df = retrieve_data(session, securities, all_fields)
+df = pd.DataFrame.from_dict(df, orient='index')
+df.index = df.index.str.slice(0,9)
+df.security = df.index.to_series()
df['loanxid'] = mapping.loanxid
df.dropna(subset=['ID_BB_UNIQUE'], inplace=True)
df.loc[df.LN_TRANCHE_SIZE.isnull(),'LN_TRANCHE_SIZE'] = df[df.LN_TRANCHE_SIZE.isnull()].AMT_ISSUED.values