def test_finder(): asset = Equity('asset-id', 'NSDQ', symbol='AAPL') class DummyBroker: def get_equities(self): return [asset] # retrieve_asset finder = AssetFinder(DummyBroker()) assert finder.retrieve_asset('asset-id') == asset with pytest.raises(SidsNotFound): finder.retrieve_asset('invalid') # retrieve_all assert finder.retrieve_all(['asset-id']) == [asset] with pytest.raises(SidsNotFound): assert finder.retrieve_all(['asset-id', 'invalid']) assert finder.retrieve_all(['asset-id', 'invalid'], default_none=True) \ == [asset, None] # retrieve_equities assert finder.retrieve_equities(['asset-id'])['asset-id'] == asset with pytest.raises(EquitiesNotFound): assert finder.retrieve_equities(['inv']) # asset should be cached until cleared assert hasattr(finder, 'asset_cache') finder.clear_cache() assert not hasattr(finder, 'asset_cache') # lookup_symbol assert finder.lookup_symbol('AAPL', None) == asset assert finder.lookup_symbol('AAPL', None, fuzzy=True) == asset with pytest.raises(SymbolNotFound): finder.lookup_symbol('invalid', None) with pytest.raises(SymbolNotFound): finder.lookup_symbol('invalid', None, fuzzy=True) # lookup_symbols assert finder.lookup_symbols(['AAPL'], None) == [asset] assert finder.lookup_symbols(['AAPL'], None, fuzzy=True) == [asset] with pytest.raises(SymbolNotFound): finder.lookup_symbols(['AAPL', 'invalid'], None) with pytest.raises(SymbolNotFound): finder.lookup_symbols(['AAPL', 'invalid'], None) # sids assert finder.sids == ['asset-id']
def get_equities(self): return [ Equity( asset, symbol=asset.upper().replace('-', ''), exchange='NYSE', start_date=self.start, end_date=self.end + pd.Timedelta('1000 days'), ) for asset in self.assets ]
def get_equities(self): return [ Equity( sid=i + 1, symbol=_num_to_symbol(i), asset_name='Test {}'.format(_num_to_symbol(i)), exchange='NYSE', start_date=pd.Timestamp('1970-01-01', tz='utc'), end_date=pd.Timestamp('2050-01-01', tz='utc'), ) for i in range(self._size) ]
def get_equities(self): assets = [] t = normalize_date(pd.Timestamp('now', tz=NY)) raw_assets = self._api.list_assets(asset_class='us_equity') for raw_asset in raw_assets: asset = Equity( raw_asset.id, raw_asset.exchange, symbol=raw_asset.symbol, asset_name=raw_asset.symbol, ) asset.start_date = t - one_day_offset if raw_asset.status == 'active' and raw_asset.tradable: asset.end_date = t + end_offset else: # if asset is not tradable, set end_date = day before asset.end_date = t - one_day_offset asset.auto_close_date = asset.end_date assets.append(asset) # register all unseen exchange name as # alias of NYSE (e.g. AMEX, ARCA, NYSEARCA.) if not default_calendar.has_calendar(raw_asset.exchange): register_calendar_alias(raw_asset.exchange, 'NYSE', force=True) return assets
def get_equities(self): assets = [] t = normalize_date(pd.Timestamp('now', tz=NY)) raw_assets = self._api.list_assets(asset_class='us_equity') for raw_asset in raw_assets: asset = Equity( raw_asset.id, raw_asset.exchange, symbol=raw_asset.symbol, asset_name=raw_asset.symbol, ) asset.start_date = t - one_day_offset if raw_asset.status == 'active' and raw_asset.tradable: asset.end_date = t + end_offset else: # this is an experimental change, if an asset is not active or # tradable, don't include it in the asset list. why? # first the logical thing - if it's not tradable - we don't # need it. now why bother? # some symbols are included more than once in the Alpaca list. # e.g VXX. one is tradable, one is not. as it happens, the # first one we iterate on is the not tradable asset. which # means when someone tries to trade it, even though there's a # tradable asset, it rejects it because we test it against the # untradable one. by doing this - we avoid this issue. # but, it fear it may cause issues (e.g if an asset was # tradable yesterday, but not tradable today. just a thought) # so I do this with caution. continue # if asset is not tradable, set end_date = day before asset.end_date = t - one_day_offset asset.auto_close_date = asset.end_date assets.append(asset) # register all unseen exchange name as # alias of NYSE (e.g. AMEX, ARCA, NYSEARCA.) if not default_calendar.has_calendar(raw_asset.exchange): register_calendar_alias(raw_asset.exchange, 'NYSE', force=True) return assets
def get_equities(self): assets = [] t = normalize_date(pd.Timestamp('now', tz='America/New_York')) raw_assets = self._api.list_assets(asset_class='us_equity') for raw_asset in raw_assets: asset = Equity( raw_asset.id, raw_asset.exchange, symbol=raw_asset.symbol, asset_name=raw_asset.symbol, ) asset.start_date = t - one_day_offset if raw_asset.status == 'active' and raw_asset.tradable: asset.end_date = t + end_offset else: # if asset is not tradable, set end_date = day before asset.end_date = t - one_day_offset asset.auto_close_date = asset.end_date assets.append(asset) return assets