aboutsummaryrefslogtreecommitdiffstats
path: root/python/rmbs/CRT_data.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/rmbs/CRT_data.py')
-rw-r--r--python/rmbs/CRT_data.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/python/rmbs/CRT_data.py b/python/rmbs/CRT_data.py
new file mode 100644
index 00000000..a4084575
--- /dev/null
+++ b/python/rmbs/CRT_data.py
@@ -0,0 +1,40 @@
+from glob import iglob
+import os
+import pandas as pd
+import datetime
+from db import dbengine
+import .load_globeop_report as load_globeop
+
+import .bbg_helpers
+
+def get_CRT_notional():
+
+ BBG_IP = ['192.168.9.65']
+ bbgstartdate = pd.datetime(2011, 1, 1)
+ path = '/home/serenitas/edwin/CRT/'
+ hist_securities = pd.read_csv(path + 'all_cusips.csv', header=None)
+ hist_securities = hist_securities + ' Mtge'
+ hist_fields = ['MTG_HIST_FACT']
+ orig_ntl_field = ['MTG_ORIG_AMT']
+
+ with bbg_helpers.init_bbg_session(BBG_IP) as session:
+ hist_data = bbg_helpers.retrieve_data(session, hist_securities[0].tolist(), hist_fields)
+
+ with bbg_helpers.init_bbg_session(BBG_IP) as session:
+ orig_ntl = bbg_helpers.retrieve_data(session, hist_securities[0].tolist(), orig_ntl_field)
+
+ hist_data1 = pd.DataFrame()
+ for cusip in hist_data:
+ new_df= pd.DataFrame()
+ new_df['notional'] = hist_data[cusip]['MTG_HIST_FACT']['Factor'] * orig_ntl[cusip]['MTG_ORIG_AMT']
+ new_df['date'] = hist_data[cusip]['MTG_HIST_FACT']['Payment Date']
+ new_df['cusip'] = cusip
+ hist_data1 = hist_data1.append(new_df)
+
+ hist_data1.to_hdf(path + 'crt_notional.hdf','notionals')
+
+def calc_CRT_notional():
+ path = '/home/serenitas/edwin/CRT/'
+ hist_data1 = pd.read_hdf(path + 'crt_notional.hdf')
+ hist_data1 = hist_data1.set_index('date')
+ return hist_data1.groupby(pd.TimeGrouper('M')).sum() \ No newline at end of file