def test_ImportCompany(self, mock_interface, mock_boto3): for party_type in ['Fund', 'Broker']: data = { 'PartyId': random_string(8), 'PartyType': party_type, 'DisplayName': random_string(12), 'LegalName': random_string(10), 'Description': random_string(20), 'BaseCurrency': random_string(3), 'AssetManagerId': self.asset_manager_id } mock_interface.reset_mock() mock_interface.return_value.search.return_value = [] result = _import_party(self.asset_manager_id, data) self.assertEqual(type(result).__name__, data['PartyType']) self.assertEqual(data['DisplayName'], result.display_name) self.assertEqual(data['LegalName'], result.legal_name) self.assertEqual(data['Description'], result.description) self.assertEqual(data['BaseCurrency'], result.base_currency) mock_interface.return_value.search.assert_called_once() mock_interface.return_value.new.assert_called_once() mock_interface.return_value.search.return_value = [result] result = _import_party(self.asset_manager_id, data) mock_interface.return_value.amend.assert_called_once()
def generate_common(asset_manager_id, asset_book_id, counterparty_book_id, asset_id, quantity, transaction_date, settlement_date, transaction_id, transaction_action, transaction_type, transaction_status): common = { 'asset_manager_id': asset_manager_id or random.randint(1, 1000), 'asset_book_id': asset_book_id or random_string(8), 'counterparty_book_id': counterparty_book_id or random_string(8), 'asset_id': asset_id or str(random.randint(1, 1000)), 'quantity': quantity or Decimal(random.randint(0, 5000)), 'transaction_date': transaction_date or datetime.date.today(), 'transaction_action': transaction_action or random.choice(list(TRANSACTION_ACTIONS)), 'transaction_id': transaction_id, 'transaction_status': transaction_status or 'New', 'transaction_type': transaction_type or 'Trade' } common['settlement_date'] = settlement_date or ( datetime.timedelta(days=2) + common['transaction_date']) return common
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.csvfile = 'WarrantsUploaderTest.csv' self.asset_ids = [random_string(8), random_string(8)] with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow([ 'Warrant', self.asset_ids[0], '123', 'Active', '123', 'USA', '123', 'USD', '01/05/09', 'Warrant', '123', '123', '123', '123', '1', 'E', '01/05/09', '01/05/09', '01/05/09', '123', '123', '123', '123', 'C', 'C', '12345', '54321', 'true', '1', 'true', '2' ]) writer.writerow([ 'Warrant', self.asset_ids[1], '123', 'Active', '123', 'USA', '123', 'USD', '01/05/09', 'Warrant', '123', '123', '123', '123', '1', 'E', '01/05/09', '01/05/09', '01/05/09', '123', '123', '123', '123', 'C', 'C', '12345', '54321', 'true', '1', 'true', '2' ])
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.csvfile = 'AutomobileUploaderTest.csv' self.asset_ids = [random_string(8), random_string(8)] with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow([ 'Automobile', self.asset_ids[0], '123', 'USA', '123', '123', '123', '01/05/09', '01/05/09', 'USD', 'Active', '01/05/09', '0', '1900', '01/05/09', '123', '123', '123', 'McLaren', 'amaas_super_car', 'White', 'R', 'M', 'super rare', 'DC', '1', 'GBR', '123', '123', 'LHD', '', '', '', '', '', '', '', '', '', '12345', '54321', 'true', '1', 'true', '2' ]) writer.writerow([ 'Automobile', self.asset_ids[1], '123', 'USA', '123', '123', '123', '01/05/09', '01/05/09', 'USD', 'Active', '01/05/09', '0', '1900', '01/05/09', '123', '123', '123', 'McLaren', 'amaas_super_car', 'White', 'R', 'M', 'super rare', 'DC', '1', 'GBR', '123', '123', 'LHD', '', '', '', '', '', '', '', '', '', '12345', '54321', 'true', '1', 'true', '2' ])
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.csvfile = 'BondFutureOptionUploaderTest.csv' self.asset_ids = [random_string(8), random_string(8)] with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow([ 'BondFutureOption', self.asset_ids[0], 'Put', 'European', '1', '', 'Cash', '', '1', '1', '', 'SGD', '', 'Active', '09/01/01', '09/01/01', '', '', '', '', '12345', '54321', 'true', '1', 'true', '2' ]) writer.writerow([ 'BondFutureOption', self.asset_ids[1], 'Call', 'European', '1', '', 'Cash', '', '1', '1', '', 'SGD', '', 'Active', '09/01/01', '09/01/01', '', '', '', '', '12345', '54321', 'true', '1', 'true', '2' ])
def generate_common(asset_manager_id, party_id, party_status): common = {'asset_manager_id': asset_manager_id or random.randint(1, 1000), 'party_id': party_id or str(random.randint(1, 1000)), 'party_status': party_status or 'Active', 'display_name': random_string(10), 'legal_name': random_string(10), 'url': random_string(10) } return common
def test_RandomString(self): test_string = random_string(6) self.assertEqual(len(test_string), 6) test_string = random_string(8) self.assertEqual(len(test_string), 8) test_string = random_string(8, numeric_only=True) non_numeric = [ letter for letter in test_string if letter not in string.digits ] self.assertEqual(non_numeric, [])
def create_equity(asset_manager_id, asset_id): """ Create an equity for use in this example. """ references = {'ISIN': Reference(reference_value=random_string(12)), 'Ticker': Reference(reference_value=random_string(8))} asset = Equity(asset_manager_id=asset_manager_id, asset_id=asset_id, currency=random.choice(currencies), references=references) return asset
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.corporate_action_ids = [random_string(8), random_string(8)] self.csvfile = 'CorporateActionUploaderTest.csv' with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow(['CorporateAction', self.corporate_action_ids[0], '09/01/01', 'Open', '1', '1', '09/01/01', '09/01/01', '1', '', '']) writer.writerow(['CorporateAction', self.corporate_action_ids[1], '09/01/01', 'Open', '1', '1', '09/01/01', '09/01/01', '1', '', ''])
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.asset_manager_ids = [random_string(8), random_string(8)] self.csvfile = 'RelationshipUploaderTest.csv' with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow(['Relationship', self.asset_manager_ids[0], '123', self.client_id, '321', 'Administrator', '543', 'Pending']) writer.writerow(['Relationship', self.asset_manager_ids[1], '123', self.client_id, '321', 'Administrator', '543', 'Pending'])
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.book_ids = [random_string(8), random_string(8)] self.csvfile = 'BookUploaderTest.csv' with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow(['Book', self.book_ids[0], 'Counterparty', 'Active', '', '', '', '', 'SGD', '', '', '']) writer.writerow(['Book', self.book_ids[1], 'Counterparty', 'Active', '', '', '', '', 'SGD', '', '', ''])
def generate_book_report(asset_manager_id=None, book_id=None, currency=None, report_type=None, business_date=None, report_timestamp=None, mtm_value=None, total_pnl=None, asset_pnl=None, fx_pnl=None, message='', report_status=None, period=None): book_report = BookReport(asset_manager_id=asset_manager_id or random.randint(1, 100), book_id=book_id or random_string(8), currency=currency or 'USD', report_type=report_type or 'MTM', business_date=business_date or datetime.date.today(), report_timestamp=report_timestamp or datetime.datetime.now(), mtm_value=mtm_value or random.random() * 100000, total_pnl=total_pnl, asset_pnl=asset_pnl, fx_pnl=fx_pnl, message=message, period=period or 'N/A', report_status=report_status or 'Active') return book_report
def generate_quote(asset_manager_id=0, asset_id=None, bid=None, ask=None): quote = Quote(asset_manager_id=asset_manager_id, asset_id=asset_id or random_string(10), bid=bid or random_decimal(), ask=ask or random_decimal(), quote_datetime=datetime.utcnow()) return quote
def test_ImmutableDicts(self): attr = self.transaction.to_dict() attr.pop('parties') # Remove parties so that the default constructor is used transaction = Transaction(**attr) transaction.parties.update({'TEST': Party(party_id=random_string(8))}) self.assertEqual(len(transaction.parties), 1) transaction2 = Transaction(**attr) self.assertEqual(len(transaction2.parties), 0)
def generate_broker(asset_manager_id=None, party_id=None, party_status=None): references = {'LEI': Reference(random_string(10))} attributes = generate_common(asset_manager_id=asset_manager_id, party_id=party_id, party_status=party_status) broker = Broker(**attributes) broker.references.update(references) broker.upsert_address('Registered', generate_address(address_primary=True)) broker.upsert_email('Office', generate_email(email_primary=True)) return broker
def generate_transaction_pnl(asset_manager_id=None, book_id=None, asset_id=None, period=None, quantity=None, business_date=None, version=None, total_pnl=None, asset_pnl=None, fx_pnl=None, additional=None, unrealised_pnl=None, realised_pnl=None, error_message=None, client_id=None, transaction_date=None, transaction_id=None, pnl_timestamp=None, pnl_status='Active', currency=None): total_pnl = random.randrange(-100000000, 2000000000) asset_pnl = random.randrange(-100000000, 1000000000) fx_pnl = total_pnl - asset_pnl transaction_pnl = TransactionPNL( asset_manager_id=asset_manager_id or random.randint(1, 10000), book_id=book_id or random_string(8), asset_id=asset_id or random_string(10), period=period or random.choice(['YTD', 'MTD', 'DTD']), transaction_date=transaction_date or datetime.date.today() + datetime.timedelta(days=-7), business_date=business_date or datetime.date.today(), additional=additional, version=version or 1, total_pnl=total_pnl or str(total_pnl), fx_pnl=fx_pnl or str(fx_pnl), asset_pnl=asset_pnl or str(asset_pnl), unrealised_pnl=unrealised_pnl, quantity=quantity, realised_pnl=realised_pnl, error_message=error_message or '', currency=currency or 'USD', transaction_id=transaction_id or random_string(16), pnl_timestamp=pnl_timestamp or datetime.datetime.utcnow(), client_id=client_id or 1, pnl_status=pnl_status) return transaction_pnl
def generate_private_investment(asset_manager_id=None, asset_id=None, client_id=None): attributes = generate_common(asset_manager_id=None, asset_id=None) """currency, display_name""" private_investment = PrivateInvestment( client_id=client_id or random_string(5), asset_issuer_id=random_string(8), category='Private Equity', sub_category='Leverage Buyout Funds', num_shares=1000, price_share=1000, share_type='Ordinary Shares', maturity_date=random_date(), lock_up_period=52, investment_term=52, **attributes) return private_investment
def generate_eod_price(asset_manager_id=0, asset_id=None, business_date=date.today(), price=None): eod_price = EODPrice(asset_manager_id=asset_manager_id, asset_id=asset_id or random_string(10), business_date=business_date, price=price or random_decimal()) return eod_price
def generate_party(asset_manager_id=None, party_id=None, party_status=None): references = {'PartyDB': Reference(random_string(10))} attributes = generate_common(asset_manager_id=asset_manager_id, party_id=party_id, party_status=party_status) party = Party(**attributes) # This is ok from a mutability perspective as the references collection doesn't trigger anything party.references.update(references) party.upsert_address('Registered', generate_address(address_primary=True)) party.upsert_email('Office', generate_email(email_primary=True)) return party
def test_UpsertLinkList(self): links = self.transaction.links.get('Multiple') random_id = random_string(8) links.add(Link(linked_transaction_id=random_id)) self.transaction.upsert_link_set('Multiple', links) links = self.transaction.links.get('Multiple') self.assertEqual(len(links), 4) # The test script inserts 3 links random_id_link = [link for link in links if link.linked_transaction_id == random_id] self.assertEqual(len(random_id_link), 1)
def generate_common(asset_manager_id=None, asset_id=None, display_name=None): common = { 'asset_manager_id': asset_manager_id or random.randint(1, 1000), 'asset_id': asset_id or str(random.randint(1, 1000)), 'currency': random.choice(['SGD', 'USD']), 'display_name': display_name or random_string(10) } return common
def generate_book(asset_manager_id=None, book_id=None, owner_id=None, party_id=None, book_type='Trading', business_unit=None): book = Book( asset_manager_id=asset_manager_id or random.randint(1, 1000), book_id=book_id or random_string(10), book_type=book_type, owner_id=owner_id or random.randint(1, 1000), base_currency=random.choice(['USD', 'SGD', 'HKD', 'EUR']), business_unit=business_unit or random.choice(['Equities', 'Emerging Markets', 'Treasury']), party_id=party_id or random_string(10)) # Can also be the asset_manager_id of the book return book
def generate_position(asset_manager_id=None, book_id=None, asset_id=None, quantity=None): position = Position(asset_manager_id=asset_manager_id or random.randint(1, 1000), book_id=book_id or random_string(8), asset_id=asset_id or str(random.randint(1, 1000)), quantity=quantity or Decimal(random.randint(1, 50000))) return position
def generate_position_pnl(asset_manager_id=None, book_id=None, asset_id=None, period=None, quantity=None, business_date=None, version=None, total_pnl=None, asset_pnl=None, fx_pnl=None, unrealised_pnl=None, realised_pnl=None, message=None, client_id=None, currency=None, pnl_timestamp=None, pnl_status='Active'): total_pnl = random.randrange(-100000000, 2000000000) asset_pnl = random.randrange(-100000000, 1000000000) fx_pnl = total_pnl - asset_pnl position_pnl = PositionPNL(asset_manager_id=asset_manager_id or random.randint(1, 10000), book_id=book_id or random_string(8), asset_id=asset_id or random_string(10), period=period or random.choice(['YTD', 'MTD', 'DTD']), business_date=business_date or datetime.date.today(), version=version or 1, total_pnl=total_pnl or str(total_pnl), fx_pnl=fx_pnl or str(fx_pnl), asset_pnl=asset_pnl or str(asset_pnl), unrealised_pnl=unrealised_pnl, quantity=quantity, realised_pnl=realised_pnl, message=message or '', currency=currency or 'USD', pnl_timestamp=pnl_timestamp or datetime.datetime.utcnow(), client_id=client_id or 1, pnl_status=pnl_status) return position_pnl
def generate_wine(asset_manager_id=None, asset_id=None): props = generate_common(asset_manager_id=asset_manager_id, asset_id=asset_id) wine = Wine(year=random_date(start_year=1950, end_year=2016), producer=random_string(5), region=random.choice(['Bordeaux', 'Burgundy', 'Tuscany', 'Napa Valley']), appellation=random.choice([None]*3 + ['Côtes du Rhône', 'Graves', 'Saint-Émilion']), classification=random.choice(list(WINE_CLASSIFICATIONS)), color=random.choice(['Red', 'White']), bottle_size=random.choice(['0.75L']*3 + ['1.5L']), bottle_in_cellar=random.choice([True]*3 + [False]), bottle_location=random_string(20), storage_cost=None, rating_type='Parker', rating_value=random.randint(93, 100), packing_type=random.choice(list(WINE_PACKING_TYPE)), to_drink_start=random_date(start_year=2000), to_drink_end=random_date(end_year=2050), comments = {'DrinkingNotes': Comment(comment_value=random_string(100))}, **props) return wine
def generate_dividend(asset_manager_id=None, corporate_action_id=None, asset_id=None): attributes = generate_common(asset_manager_id=asset_manager_id, corporate_action_id=corporate_action_id, asset_id=asset_id) dividend = Dividend(dividend_rate=Decimal(random.random()).quantize( Decimal('1.00')), dividend_asset_id=random_string(10), **attributes) return dividend
def generate_equity(asset_manager_id, asset_id, share_class='Common', currency='USD'): equity = Equity(asset_manager_id=asset_manager_id or random.randint(1, 1000), asset_id=asset_id or random_string(5), share_class=share_class, asset_status='Active', currency=currency or 'USD') return equity
def test_MultipleLink(self): transaction = self.transactions_interface.new(self.transaction) links = transaction.links.get('Multiple') self.assertEqual(len(links), 3) # The test script inserts 3 links # Add a link random_id = random_string(8) transaction.add_link('Multiple', linked_transaction_id=random_id) transaction = self.transactions_interface.amend(transaction) self.assertEqual(len(transaction.links.get('Multiple')), 4) transaction.remove_link('Multiple', linked_transaction_id=random_id) transaction = self.transactions_interface.amend(transaction) self.assertEqual(len(transaction.links.get('Multiple')), 3)
def setUp(self): self.longMessage = True # Print complete error message on failure self.asset_manager_id = self.client_id = 1 self.asset_manager_ids = [random_string(8), random_string(8)] self.csvfile = 'AssetManagerUploaderTest.csv' with open(self.csvfile, 'r+', newline='') as readfile: reader = csv.reader(readfile) for row in reader: header = row break with open(self.csvfile, 'w+', newline='') as writefile: writer = csv.writer(writefile) writer.writerow(header) writer.writerow([ 'AssetManager', 'Bank', self.asset_manager_ids[0], 'Active', '123', 'Basic', '321', 'UTC', '5pm' ]) writer.writerow([ 'AssetManager', 'Bank', self.asset_manager_ids[1], 'Active', '123', 'Basic', '321', 'UTC', '5pm' ])
def test_ImportIndividualParty(self, mock_interface, mock_boto3): data = { 'PartyId': random_string(8), 'PartyType': 'Individual', 'DisplayName': random_string(12), 'Surname': random_string(10), 'GivenNames': random_string(10), 'AssetManagerId': self.asset_manager_id } mock_interface.return_value.search.return_value = [] result = _import_party(self.asset_manager_id, data) self.assertEqual(type(result).__name__, data['PartyType']) self.assertEqual(data['Surname'], result.surname) self.assertEqual(data['GivenNames'], result.given_names) mock_interface.return_value.search.assert_called_once() mock_interface.return_value.new.assert_called_once() mock_interface.reset_mock() mock_interface.return_value.search.return_value = [result] result = _import_party(self.asset_manager_id, data) mock_interface.return_value.search.assert_called_once() mock_interface.return_value.amend.assert_called_once()