aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/position.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/python/position.py b/python/position.py
index 5d95a488..7c9de7fe 100644
--- a/python/position.py
+++ b/python/position.py
@@ -57,20 +57,22 @@ def backpopulate_marks(begin_str='2015-01-15', end_str='2015-07-15'):
def update_securities(engine, session, workdate):
field = {'Corp': 'PREV_CPN_DT', 'Mtge': 'START_ACC_DT'}
- all_securities = get_list(engine)
+ securities = get_list(engine)
+ securities = securities[securities.paid_down.isnull()]
conn = engine.raw_connection()
- for bbg_type in ['Corp', 'Mtge']:
- securities = all_securities[all_securities.index.str.endswith(bbg_type)]
- data = retrieve_data(session, securities.index.tolist(), [field[bbg_type], 'CUR_CPN'])
- data = pd.DataFrame.from_dict(data, orient='index')
- m = securities.merge(data, left_index=True, right_index=True)
- with conn.cursor() as c:
- for r in m.to_dict('records'):
- if r[field[bbg_type]]<workdate:
- c.execute("UPDATE securities SET start_accrued_date=%({0})s "
- ",coupon=%(CUR_CPN)s WHERE identifier=%(identifier)s".format(field[bbg_type]),
- r)
- conn.commit()
+ 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 = pd.DataFrame.from_dict(data, orient='index')
+ m = securities.merge(data, left_index=True, right_index=True)
+ with conn.cursor() as c:
+ for r in m.to_dict('records'):
+ if r[field[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]]),
+ r)
+ conn.commit()
def init_fx(session, engine, startdate):
currencies = ['EURUSD', 'CADUSD']
@@ -144,7 +146,7 @@ def populate_cashflow_history(engine, session, workdate=None):
if __name__=="__main__":
engine = create_engine('postgresql://dawn_user@debian/dawndb')
if len(sys.argv)>1:
- workdate = pd.Timestamp(sys.argv[1]).date()
+ workdate = pd.Timestamp(sys.argv[1])
workdate = pd.datetime.today()
with init_bbg_session(BBG_IP) as session:
update_securities(engine, session, workdate)