diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/bbg_helpers.py | 5 | ||||
| -rw-r--r-- | python/position.py | 19 |
2 files changed, 14 insertions, 10 deletions
diff --git a/python/bbg_helpers.py b/python/bbg_helpers.py index 716ea56a..20db812e 100644 --- a/python/bbg_helpers.py +++ b/python/bbg_helpers.py @@ -57,8 +57,9 @@ def event_loop(session, request): return def get_pythonvalue(e): - if e.datatype() in [blpapi.DataType.DATE, blpapi.DataType.DATETIME]: - t = e.getValue() + if e.datatype() == blpapi.DataType.DATE: + return pd.to_datetime(e.getValue()) + elif e.datatype() == blpapi.DataType.DATETIME: if isinstance(t, datetime.time): return t else: diff --git a/python/position.py b/python/position.py index d5100659..5000cf4a 100644 --- a/python/position.py +++ b/python/position.py @@ -66,13 +66,15 @@ def update_securities(engine, session, workdate): ['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)] + 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'): - if r[field[r['bbg_type']]] < workdate: - c.execute("UPDATE securities SET start_accrued_date=%({0})s " - ",coupon=%(CUR_CPN)s WHERE identifier=%(identifier)s".format(field[r['bbg_type']]), + accrued_field = field[r['bbg_type']] + 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) conn.commit() conn.close() @@ -217,8 +219,9 @@ def update_swap_rates(conn, session, def populate_cashflow_history(engine, session, workdate=None): securities = get_list(engine, workdate) - data = retrieve_data(session, securities.index.tolist(), ['HIST_CASH_FLOW', 'MTG_HIST_CPN', - 'FLT_CPN_HIST', 'HIST_INTEREST_DISTRIBUTED']) + data = retrieve_data(session, securities.index.tolist(), + ['HIST_CASH_FLOW', 'MTG_HIST_CPN', + 'FLT_CPN_HIST', 'HIST_INTEREST_DISTRIBUTED']) fixed_coupons = {'XS0306416982 Mtge': 7.62, '91927RAD1 Mtge': 6.77} conn = engine.raw_connection() @@ -248,7 +251,7 @@ def populate_cashflow_history(engine, session, workdate=None): continue else: logging.error("No cashflows for the given security") - identifier = securities.loc[k,'identifier'] + identifier = securities.loc[k, 'identifier'] to_insert['identifier'] = identifier with conn.cursor() as c: c.execute("DELETE FROM cashflow_history WHERE identifier=%s", (identifier,)) @@ -266,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]) + workdate = pd.Timestamp(sys.argv[1]).date() else: - workdate = pd.datetime.today() + workdate = pd.Timestamp.now().date() with init_bbg_session(BBG_IP) as session: update_securities(dawn_engine, session, workdate) populate_cashflow_history(dawn_engine, session, workdate) |
