blob: a4084575d24a85ef84d6a31d6a35fc6f5d7da0cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()
|