def create_assets(asset_manager_id): singtel_symbol = 'Z77.SI' singtel_references = {'ISIN': Reference(reference_value='SG1T75931496'), 'Ticker': Reference(reference_value=singtel_symbol)} singtel = Equity(asset_manager_id=asset_manager_id, asset_id=singtel_symbol, currency='SGD', references=singtel_references) assets_interface.new(singtel) return singtel
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 create_assets(asset_manager_id): hsbc_symbol = '0005.HK' hsbc_references = { 'ISIN': Reference(reference_value='GB0005405286'), 'Ticker': Reference(reference_value=hsbc_symbol) } hsbc = Equity(asset_manager_id=asset_manager_id, asset_id=hsbc_symbol, currency='HKD', references=hsbc_references) assets_interface.new(hsbc) return hsbc
def __init__(self, asset_manager_id, corporate_action_id, record_date, corporate_action_status='Open', asset_id=None, party_id=None, declared_date=None, settlement_date=None, elective=False, message=None, description='', references=None, *args, **kwargs): self.asset_manager_id = asset_manager_id self.corporate_action_id = corporate_action_id or uuid.uuid4().hex self.corporate_action_type = self.__class__.__name__ self.corporate_action_status = corporate_action_status self.record_date = record_date self.declared_date = declared_date or datetime.date.today() self.settlement_date = settlement_date or self.record_date self.asset_id = asset_id self.party_id = party_id self.elective = elective self.message = message self.description = description # Defaults are here not in constructor for mutability reasons. self.references = references.copy() if references else {} self.references['AMaaS'] = Reference( reference_value=self.corporate_action_id ) # Upserts the AMaaS Reference super(CorporateAction, self).__init__(*args, **kwargs)
def create_jgb(asset_manager_id): jgb_symbol = 'JB355' jgb_references = { 'ISIN': Reference(reference_value='JP1234567890'), 'Ticker': Reference(reference_value=jgb_symbol) } jgb = BondGovernment(asset_manager_id=asset_manager_id, asset_id=jgb_symbol, currency='JPY', references=jgb_references, coupon=Decimal('0.1'), par=Decimal(50000), pay_frequency='Semi') assets_interface.new(jgb) return jgb
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_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 generate_corporate_action(asset_manager_id=None, corporate_action_id=None, asset_id=None): common = generate_common(asset_manager_id=asset_manager_id, corporate_action_id=corporate_action_id, asset_id=asset_id) corporate_action = CorporateAction(**common) references = { ref_type: Reference(reference_value=random_string(10)) for ref_type in REFERENCE_TYPES } corporate_action.references.update(references) return corporate_action
def __init__(self, asset_manager_id, fungible, asset_issuer_id=None, asset_id=None, asset_status='Active', country_id=None, venue_id=None, currency=None, issue_date=date.min, roll_price=True, display_name='', description='', maturity_date=date.max, comments=None, links=None, references=None, client_additional=None, *args, **kwargs): self.asset_manager_id = asset_manager_id self.asset_id = asset_id or uuid.uuid4().hex if not hasattr( self, 'asset_class' ): # A more specific child class may have already set this self.asset_class = 'Asset' # This can be overridden if necessary but I think it probably shouldn't self.asset_type_display = ' '.join( re.findall('[A-Z][^A-Z]*', self.__class__.__name__)) self.asset_type = self.__class__.__name__ self.fungible = fungible self.asset_issuer_id = asset_issuer_id self.asset_status = asset_status self.country_id = country_id self.venue_id = venue_id self.currency = currency self.issue_date = issue_date self.maturity_date = maturity_date self.roll_price = roll_price self.display_name = display_name self.description = description self.client_additional = client_additional # A field to allow people to build their own assets # Defaults are here not in constructor for mutability reasons. self.comments = comments.copy() if comments else {} self.links = links.copy() if links else {} self.references = references.copy() if references else {} self.references['Argomi'] = Reference( reference_value=self.asset_id) # Upserts the Argomi Reference super(Asset, self).__init__(*args, **kwargs)
def generate_asset(asset_manager_id=None, asset_id=None, fungible=None, roll_price=None, country_id=None): common = generate_common(asset_manager_id=asset_manager_id, asset_id=asset_id) common['fungible'] = random.choice([True, False ]) if fungible is None else fungible common['roll_price'] = random.choice( [True, False]) if roll_price is None else roll_price common['country_id'] = country_id or random.choice( ['SGP', 'USA', 'GBR', 'JPN']) asset = Asset(**common) references = { ref_type: Reference(reference_value=random_string(10)) for ref_type in REFERENCE_TYPES } asset.references.update(references) return asset
def generate_transaction(asset_manager_id=None, asset_book_id=None, counterparty_book_id=None, asset_id=None, quantity=None, transaction_date=None, transaction_id=None, price=None, transaction_action=None, transaction_type=None, settlement_date=None, transaction_status=None, transaction_currency=None, settlement_currency=None, net_affecting_charges=None, charge_currency=None): # Explicitly handle price is None (in case price is 0) price = Decimal(random.uniform(1.0, 1000.0)).quantize( Decimal('0.01')) if price is None else price transaction_currency = transaction_currency or random.choice( ['SGD', 'USD']) settlement_currency = settlement_currency or transaction_currency or random.choice( ['SGD', 'USD']) common = generate_common(asset_manager_id=asset_manager_id, asset_book_id=asset_book_id, counterparty_book_id=counterparty_book_id, asset_id=asset_id, quantity=quantity, transaction_date=transaction_date, transaction_id=transaction_id, transaction_action=transaction_action, transaction_status=transaction_status, transaction_type=transaction_type, settlement_date=settlement_date) transaction = Transaction(price=price, transaction_currency=transaction_currency, settlement_currency=settlement_currency, **common) charges = { charge_type: Charge(charge_value=Decimal(random.uniform(1.0, 100.0)).quantize( Decimal('0.01')), currency=charge_currency or random.choice(['USD', 'SGD']), net_affecting=net_affecting_charges or random.choice([True, False])) for charge_type in CHARGE_TYPES } links = { 'Single': Link(linked_transaction_id=random_string(8)), 'Multiple': {Link(linked_transaction_id=random_string(8)) for x in range(3)} } codes = { code_type: Code(code_value=random_string(8)) for code_type in CODE_TYPES } comments = { comment_type: Comment(comment_value=random_string(8)) for comment_type in COMMENT_TYPES } parties = { party_type: Party(party_id=random_string(8)) for party_type in PARTY_TYPES } rates = { rate_type: Rate(rate_value=Decimal(random.uniform(1.0, 100.0)).quantize( Decimal('0.01'))) for rate_type in RATE_TYPES } references = { ref_type: Reference(reference_value=random_string(10)) for ref_type in REFERENCE_TYPES } transaction.charges.update(charges) transaction.codes.update(codes) transaction.comments.update(comments) transaction.links.update(links) transaction.parties.update(parties) transaction.rates.update(rates) transaction.references.update(references) return transaction
def __init__(self, asset_manager_id, asset_book_id, counterparty_book_id, transaction_action, asset_id, quantity, transaction_date, settlement_date, price, transaction_currency, settlement_currency=None, asset=None, execution_time=None, transaction_type="Trade", transaction_id=None, transaction_status="New", charges=None, codes=None, comments=None, links=None, parties=None, rates=None, references=None, *args, **kwargs): """ :param asset_manager_id: :param asset_book_id: :param counterparty_book_id: :param transaction_action: :param asset_id: :param quantity: :param transaction_date: :param settlement_date: :param price: :param transaction_currency: :param settlement_currency: The currency in which the transaction will be settled. Defaults to the transaction_currency if not specified. :param asset: :param execution_time: :param transaction_type: :param transaction_id: :param transaction_status: :param charges: :param codes: :param comments: :param links: :param parties: :param rates: :param references: :param args: :param kwargs: """ self.transaction_id = transaction_id or uuid.uuid4().hex self.asset_manager_id = asset_manager_id self.asset_book_id = asset_book_id self.counterparty_book_id = counterparty_book_id self.transaction_action = transaction_action self.asset_id = asset_id # This is duplicated on the child asset. Remove? self.quantity = quantity self.transaction_date = transaction_date self.settlement_date = settlement_date self.price = price self.transaction_currency = transaction_currency self.settlement_currency = settlement_currency or transaction_currency self.transaction_type = transaction_type self.transaction_status = transaction_status # Cannot be in method signature or the value gets bound to the constructor call self.execution_time = execution_time or datetime.datetime.utcnow() # Defaults are here not in constructor for mutability reasons. self.charges = charges.copy() if charges else {} self.codes = codes.copy() if codes else {} self.comments = comments.copy() if comments else {} self.links = links.copy() if links else {} self.parties = parties.copy() if parties else {} self.rates = rates.copy() if rates else {} self.references = references.copy() if references else {} self.references["AMaaS"] = Reference( reference_value=self.transaction_id) # Upserts the AMaaS Reference self.postings = [] self.asset = asset super(Transaction, self).__init__(*args, **kwargs)
def _import_transaction(asset_manager_id, rowdata): charge_columns = [ c for c in rowdata.keys() if c.startswith(CHARGES_PREFIX) ] charges = { column.replace(CHARGES_PREFIX, ''): rowdata.pop(column) for column in charge_columns if rowdata.get(column) } party_columns = [c for c in rowdata.keys() if c.startswith(PARTIES_PREFIX)] parties = { column.replace(PARTIES_PREFIX, ''): rowdata.pop(column) for column in party_columns if rowdata.get(column) } rate_columns = [c for c in rowdata.keys() if c.startswith(RATES_PREFIX)] rates = { column.replace(RATES_PREFIX, ''): rowdata.pop(column) for column in rate_columns if rowdata.get(column) } rowdata = {to_snake_case(key): value for key, value in rowdata.items()} asset_type = rowdata.pop('asset_type') if not asset_type: return asset_id = rowdata['asset_id'] settlement_date = parse(rowdata['settlement_date']) if asset_type in ['ForeignExchangeSpot', 'ForeignExchangeForward']: underlying = asset_id # this should be handled by our SDK ideally prefix, model = ('SPT', ForeignExchangeSpot) \ if asset_type == 'ForeignExchangeSpot' \ else ('FWD', ForeignExchangeForward) asset_id = f'{prefix}{asset_id}{settlement_date.strftime("%Y%m%d")}' rowdata['asset_id'] = asset_id params = { 'asset_manager_id': asset_manager_id, 'asset_id': asset_id, 'underlying': underlying, 'settlement_date': rowdata['settlement_date'], 'currency': rowdata['transaction_currency'] } if asset_type == 'ForeignExchangeForward': params['fixing_date'] = rowdata.get('fixing_date') params['forward_rate'] = rowdata['price'] asset = model(**params) asset.references['CCY Pair'] = Reference(underlying, reference_primary=True) asset_api = AssetsInterface(environment=ENVIRONMENT) existing_asset = asset_api.search(asset_manager_id=asset_manager_id, asset_ids=[asset_id]) asset = asset_api.new(asset) if not existing_asset \ else asset_api.amend(asset) transaction = Transaction(**rowdata) transaction_api = TransactionsInterface(environment=ENVIRONMENT) existing_transaction = transaction_api.search( asset_manager_id=asset_manager_id, transaction_ids=[rowdata['transaction_id']]) for party_type, party_id in parties.items(): transaction.parties[party_type] = TransactionParty(party_id) for charge_type, charge_value in charges.items(): transaction.charges[charge_type] = Charge( charge_value, rowdata['transaction_currency']) for rate_type, rate_value in rates.items(): transaction.rates[rate_type] = Rate(rate_value) if not existing_transaction: transaction_api.new(transaction) else: transaction_api.amend(transaction) return transaction