diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/position.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/python/position.py b/python/position.py index cb467947..4af08467 100644 --- a/python/position.py +++ b/python/position.py @@ -18,7 +18,7 @@ def get_list( ): if workdate: positions = pd.read_sql_query( - "SELECT identifier, bbg_type FROM " "list_positions(%s, %s, %s, %s)", + "SELECT identifier, bbg_type FROM list_positions(%s, %s, %s, %s)", engine, params=(workdate, asset_class, include_unsettled, fund), ) @@ -303,17 +303,21 @@ def update_cash_rates(conn, session, start_date=None): conn.commit() -def populate_cashflow_history(engine, session, workdate=None, fund="SERCGMAST"): - securities = get_list(engine, workdate, fund=fund) +def populate_cashflow_history(engine, session, workdate=None, funds=("SERCGMAST",)): + securities = {} + for fund in funds: + secs = get_list(engine, workdate, fund=fund) + for sec in secs.itertuples(): + if sec.Index not in securities: + securities[sec.Index] = sec.identifier data = retrieve_data( session, - securities.index.tolist(), + securities, ["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() for k, v in data.items(): - identifier = securities.loc[k, "identifier"] if "HIST_CASH_FLOW" in v: to_insert = v["HIST_CASH_FLOW"].merge( v["MTG_HIST_CPN"], @@ -350,12 +354,14 @@ def populate_cashflow_history(engine, session, workdate=None, fund="SERCGMAST"): else: # damn you XS0299146992 ! continue else: - logging.error(f"No cashflows for security {identifier}") + logging.error(f"No cashflows for security {securities[k]}") continue - to_insert["identifier"] = identifier + to_insert["identifier"] = securities[k] with conn.cursor() as c: - c.execute("DELETE FROM cashflow_history WHERE identifier=%s", (identifier,)) + c.execute( + "DELETE FROM cashflow_history WHERE identifier=%s", (securities[k],) + ) conn.commit() to_insert.to_sql("cashflow_history", engine, if_exists="append", index=False) with conn.cursor() as c: @@ -381,8 +387,9 @@ if __name__ == "__main__": serenitas_conn = serenitas_pool.getconn() with init_bbg_session(BBG_IP) as session: update_securities(dawn_engine, session, args.workdate) - for fund in ("SERCGMAST", "BRINKER", "BOWDST"): - populate_cashflow_history(dawn_engine, session, args.workdate, fund) + populate_cashflow_history( + dawn_engine, session, args.workdate, ("SERCGMAST", "BRINKER", "BOWDST") + ) update_fx(dawn_conn, session, ["EURUSD", "CADUSD"]) update_swap_rates(serenitas_conn, session) update_cash_rates(serenitas_conn, session) |
