def test_match(self): list_a, list_b = create_list1() matched_list = match(list_a, list_b, is_matched) self.assertEqual(len(matched_list), 3) self.assertEqual(matched_list[0], (1, -1)) self.assertEqual(matched_list[1], (2, -2)) self.assertEqual(matched_list[2], (3, -3))
def test_match2(self): list_a, list_b = create_list2() matched_list = match(list_a, list_b, is_matched) self.assertEqual(len(matched_list), 3) self.assertEqual(matched_list[0], (1, -1)) self.assertEqual(matched_list[1], (4.0625, -4)) self.assertEqual(matched_list[2], (3, -3))
def create_fx_pairs(transaction_list): """ Since FXPurch/FXSale always occur in pairs, read the transaction_list, create a list of such fx buy/sell pairs. """ buy_list, sell_list = filter_fx_trade_list(transaction_list) if len(buy_list) != len(sell_list): logger.error( 'create_fx_pairs(): {0} fx buy, {1} fx sell, not equal'.format( len(buy_list), len(sell_list))) raise InconsistentFXTrades() return match(buy_list, sell_list, is_fx_trade_pair)
def refine_price(record_list, ft_records): """ Refine the price for all transfer records. Here we expect the CSA, IATSA prices are the same as in the transaction file, but CSW and IATSW prices are different because the latter uses book value to derive the price. Return the updated list of CSA/CSW/IATSA/IATSW records. Other types of records (CALL, TNDL) are ignored. """ for (transfer, ft_transfer) in match(filter_transfer(record_list), ft_records, map_transfer): if ft_transfer['TRADEPRC'] > 0: transfer['Price'] = ft_transfer['TRADEPRC'] else: transfer['Price'] = (abs(ft_transfer['CPTLAWLCL']) - abs( ft_transfer['ACCRBAS'] * ft_transfer['FXRATE'])) / ft_transfer['QTY'] * 100 return record_list
def test_match4(self): list_a, list_b = create_list4() with self.assertRaises(MatchedItemNotFound): matched_list = match(list_a, list_b, is_matched)