def test_convert12307_2(self): file1 = get_current_path() + '\\samples\\12307-20161111.xls' file2 = get_current_path() + '\\samples\\12307-20161116.xls' files = [file1, file2] records = convert12307(files) self.assertEqual(len(records), 7) self.verify_record1(records[0]) self.verify_record2(records[4]) self.verify_record3(records[6])
def test_read_transaction_file4(self): file = join(get_current_path(), 'samples', 'bond_order_error3.xls') output_list = [] error_list = [] read_transaction_file(file, output_list, error_list) self.assertEqual(len(output_list), 0) self.assertEqual(len(error_list), 1)
def test_convert12307(self): file = get_current_path() + '\\samples\\12307-20161111.xls' files = [file] records = convert12307(files) self.assertEqual(len(records), 5) self.verify_record1(records[0]) self.verify_record2(records[4])
def test_convert_12734(self): files = [get_current_path() + '\\samples\\bond_order_sample1.xls'] records = convert12734(files) self.assertEqual(len(records), 4) self.verify_record1(records[0]) self.verify_record2(records[2]) self.verify_record3(records[3])
def get_geneva_investment_id(trade_info): """ As portfolio 12307 is an equity portfolio, the Geneva investment id is the Bloomberg ticker without the yellow key, e.g., '11 HK'. So assumptions for this function are: 1. All investment is equity. 2. In the holdings of the portfolio, the ISIN number to ticker mapping is unique. """ # use a function attribute to store the lookup table, as there is only # one instance of a function, all invocations access the same variable. # see http://stackoverflow.com/questions/279561/what-is-the-python-equivalent-of-static-variables-inside-a-function if 'i_lookup' not in get_geneva_investment_id.__dict__: get_geneva_investment_id.i_lookup = {} investment_lookup = get_geneva_investment_id.i_lookup if len(investment_lookup) == 0: lookup_file = get_current_path() + '\\investmentLookup.xls' initialize_investment_lookup(investment_lookup, lookup_file) # return (name, investment_id) logger.debug('get_geneva_investment_id(): trade date {0}'.format( trade_info['Trd Dt'])) return investment_lookup[trade_info['ISIN']]
def test_read_transaction_file6(self): file = join(get_current_path(), 'samples', 'bond_order_error4.xls') output_list = [] error_list = [] read_transaction_file(file, output_list, error_list) self.assertEqual(len(output_list), 1) self.assertEqual(len(error_list), 1) self.verify_bond_order4(output_list[0]) self.assertEqual(error_list[0], 15) # error occurred on row 15
def test_read_transaction_file(self): file = join(get_current_path(), 'samples', 'bond_order_sample1.xls') output_list = [] error_list = [] read_transaction_file(file, output_list, error_list) self.assertEqual(len(output_list), 4) self.assertEqual(len(error_list), 0) self.verify_bond_order1(output_list[0]) self.verify_bond_order2(output_list[3])
def test_ftcsa2(self): match_file = get_current_path( ) + '\\samples\\12366 match results 0118 morning.xlsx' transaction_file = get_current_path( ) + '\\samples\\transactions 12366 no initial pos.xls' match_status = read_match_status(match_file) isin_list = [entry[2] for entry in match_status] transaction_list = [] read_transaction_file(transaction_file, isin_list, transaction_list) # print(len(transaction_list)) matched_transaction_list, bad_isin_list = filter_matched_transaction( transaction_list, match_status) records = convert_to_geneva_records(matched_transaction_list) fix_duplicate_key_value(records) try: verify_records(match_status, records, bad_isin_list) except: self.fail('verify records function failed') # from a IATSA transaction self.verify_record6( self.find_record(records, 'FR0013101599 HTM', 'Buy', 28000000))
def test_ftcsa(self): match_file = get_current_path( ) + '\\samples\\12229 match results 0118 morning.xlsx' transaction_file = get_current_path( ) + '\\samples\\transactions 12229 no initial pos.xls' match_status = read_match_status(match_file) isin_list = [entry[2] for entry in match_status] transaction_list = [] read_transaction_file(transaction_file, isin_list, transaction_list) matched_transaction_list, bad_isin_list = filter_matched_transaction( transaction_list, match_status) records = convert_to_geneva_records(matched_transaction_list) fix_duplicate_key_value(records) try: verify_records(match_status, records, bad_isin_list) except: self.fail('verify records function failed') # from a CSA transaction self.verify_record1( self.find_record(records, 'USG46715AB73 HTM', 'Buy', 3750000)) # from a CSW transaction self.verify_record2( self.find_record(records, 'USG46715AC56 HTM', 'Sell', 4500000)) # from a CALLED transaction self.verify_record3( self.find_record(records, 'US06406JET88 HTM', 'Sell', 100000)) # from a TNDRL transaction self.verify_record4( self.find_record(records, 'USY97279AB28 HTM', 'Sell', 10900000)) # from a IATSW transaction self.verify_record5( self.find_record(records, 'FR0013101599 HTM', 'Sell', 17200000))
def test_get_geneva_investment_id(self): lookup_file = get_current_path( ) + '\\samples\\sample_investmentLookup.xls' # investment_lookup = get_geneva_investment_id.i_lookup # self.assertEqual(investment_lookup, 28) trade_info = {} trade_info['ISIN'] = 'US01609W1027' # fist name, ticker = get_geneva_investment_id(trade_info) self.assertEqual(ticker, 'BABA US') trade_info['ISIN'] = 'KYG981491007' # last name, ticker = get_geneva_investment_id(trade_info) self.assertEqual(ticker, '1128 HK') trade_info['ISIN'] = 'HK0941009539' name, ticker = get_geneva_investment_id(trade_info) self.assertEqual(ticker, '941 HK') self.assertEqual(name, 'CHINA MOBILE LTD') trade_info['ISIN'] = 'KYG5636C1078' name, ticker = get_geneva_investment_id(trade_info) self.assertEqual(ticker, '3339 HK') self.assertEqual(name, 'LONKING HOLDINGS LTD')
def test_read_file(self): files = [get_current_path() + '\\samples\\sample_FT_12229.xls'] records = convert_ft(files) self.assertEqual(len(records), 3) self.verify_record1(records[0]) self.verify_record2(records[2])
def get_worksheet(self, filename): filename = get_current_path() + filename wb = open_workbook(filename=filename) ws = wb.sheet_by_index(0) return ws