aboutsummaryrefslogtreecommitdiffstats
path: root/python/position.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/position.py')
-rw-r--r--python/position.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/python/position.py b/python/position.py
index 373d965f..dd142cf7 100644
--- a/python/position.py
+++ b/python/position.py
@@ -15,13 +15,13 @@ def get_list(engine, workdate=None, asset_class=None, include_unsettled=True):
if workdate:
positions = pd.read_sql_query("select identifier, bbg_type from list_positions(%s, %s, %s)",
engine,
- params=(workdate, asset_class, include_unsettled))
+ params=(workdate.date(), asset_class, include_unsettled))
positions.loc[positions.identifier.str.len() <= 11, 'cusip'] = positions.identifier.str.slice(stop=9)
positions.loc[positions.identifier.str.len() == 12, 'isin'] = positions.identifier
else:
positions = pd.read_sql_table("securities", engine)
positions['bbg_id'] = positions.cusip.where(positions.cusip.notnull(), positions['isin']) + \
- ' ' + positions.bbg_type
+ ' ' + positions.bbg_type
positions.set_index('bbg_id', inplace=True)
return positions
@@ -34,7 +34,7 @@ def get_list_range(engine, begin, end, asset_class=None):
positions.loc[positions.identifier.str.len() <= 11, 'cusip'] = positions.identifier.str.slice(stop=9)
positions.loc[positions.identifier.str.len() == 12, 'isin'] = positions.identifier
positions['bbg_id'] = positions.cusip.where(positions.cusip.notnull(), positions['isin']) + \
- ' ' + positions.bbg_type
+ ' ' + positions.bbg_type
positions.set_index('bbg_id', inplace=True)
return positions
@@ -65,14 +65,14 @@ def update_securities(engine, session, workdate):
data = retrieve_data(session, securities.index.tolist(),
['PREV_CPN_DT', 'START_ACC_DT', 'CUR_CPN', 'CPN_ASOF_DT'])
data = pd.DataFrame.from_dict(data, orient='index')
- data = data[data.CPN_ASOF_DT.isnull() |(data.CPN_ASOF_DT<=workdate)]
+ data = data[data.CPN_ASOF_DT.isnull() |(data.CPN_ASOF_DT <= workdate)]
m = securities.merge(data, left_index=True, right_index=True)
conn = engine.raw_connection()
with conn.cursor() as c:
for r in m.to_dict('records'):
accrued_field = field[r['bbg_type']]
- if r[accrued_field].date() < workdate:
+ if r[accrued_field] < workdate:
c.execute(f"UPDATE securities SET start_accrued_date=%({accrued_field})s "
",coupon=%(CUR_CPN)s WHERE identifier=%(identifier)s",
r)
@@ -269,9 +269,9 @@ if __name__=="__main__":
dawn_engine = create_engine('postgresql://dawn_user@debian/dawndb')
dawn_conn = dawn_engine.raw_connection()
if len(sys.argv) > 1:
- workdate = pd.Timestamp(sys.argv[1]).date()
+ workdate = pd.Timestamp(sys.argv[1])
else:
- workdate = pd.Timestamp.now().date()
+ workdate = pd.Timestamp.now().normalize()
with init_bbg_session(BBG_IP) as session:
update_securities(dawn_engine, session, workdate)
populate_cashflow_history(dawn_engine, session, workdate)