aboutsummaryrefslogtreecommitdiffstats
path: root/python/position.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/position.py')
-rw-r--r--python/position.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/python/position.py b/python/position.py
index f4420e10..3ecab213 100644
--- a/python/position.py
+++ b/python/position.py
@@ -73,16 +73,19 @@ def populate_cashflow_history(session, conn, workdate):
securities['bbg_id'] = securities.cusip.where(securities.cusip.notnull(), securities['isin']) + \
' ' + securities.bbg_type
securities.set_index('bbg_id', inplace=True)
- data = retrieve_data(session, securities.index.tolist(), ['HIST_CASH_FLOW'])
+ #we also download MTG_HIST_CPN because the data is more accurate
+ data = retrieve_data(session, securities.index.tolist(), ['HIST_CASH_FLOW', 'MTG_HIST_CPN'])
for k, v in data.items():
- to_insert = v.get('HIST_CASH_FLOW')
- if to_insert is not None:
+ hist_cf = v.get('HIST_CASH_FLOW')
+ hist_cpn = v.get('MTG_HIST_CPN')
+ if hist_cf is not None:
identifier = securities.loc[k,'identifier']
- to_insert['identifier'] = identifier
+ hist_cf['identifier'] = identifier
+ to_insert = hist_cf.merge(hist_cpn, left_on='Payment Date', right_on='Payment Date')
with conn.cursor() as c:
c.execute("DELETE FROM cashflow_history WHERE identifier=%s", (identifier,))
conn.commit()
- to_insert.rename(columns={'Coupon': 'coupon',
+ to_insert.rename(columns={'Coupon_y': 'coupon',
'Interest': 'interest',
'Payment Date': 'date',
'Principal Balance': 'principal_bal',