本文整理汇总了Python中zipline.assets.AssetFinder.lookup_symbol方法的典型用法代码示例。如果您正苦于以下问题:Python AssetFinder.lookup_symbol方法的具体用法?Python AssetFinder.lookup_symbol怎么用?Python AssetFinder.lookup_symbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipline.assets.AssetFinder
的用法示例。
在下文中一共展示了AssetFinder.lookup_symbol方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lookup_symbol
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_lookup_symbol(self):
# Incrementing by two so that start and end dates for each
# generated Asset don't overlap (each Asset's end_date is the
# day after its start date.)
dates = pd.date_range("2013-01-01", freq="2D", periods=5, tz="UTC")
df = pd.DataFrame.from_records(
[
{
"sid": i,
"symbol": "existing",
"start_date": date.value,
"end_date": (date + timedelta(days=1)).value,
"exchange": "NYSE",
}
for i, date in enumerate(dates)
]
)
self.env.write_data(equities_df=df)
finder = AssetFinder(self.env.engine)
for _ in range(2): # Run checks twice to test for caching bugs.
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol("NON_EXISTING", dates[0])
with self.assertRaises(MultipleSymbolsFound):
finder.lookup_symbol("EXISTING", None)
for i, date in enumerate(dates):
# Verify that we correctly resolve multiple symbols using
# the supplied date
result = finder.lookup_symbol("EXISTING", date)
self.assertEqual(result.symbol, "EXISTING")
self.assertEqual(result.sid, i)
示例2: test_lookup_symbol
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_lookup_symbol(self):
# Incrementing by two so that start and end dates for each
# generated Asset don't overlap (each Asset's end_date is the
# day after its start date.)
dates = pd.date_range('2013-01-01', freq='2D', periods=5, tz='UTC')
df = pd.DataFrame.from_records(
[
{
'sid': i,
'symbol': 'existing',
'start_date': date.value,
'end_date': (date + timedelta(days=1)).value,
'exchange': 'NYSE',
}
for i, date in enumerate(dates)
]
)
self.env.write_data(equities_df=df)
finder = AssetFinder(self.env.engine)
for _ in range(2): # Run checks twice to test for caching bugs.
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('NON_EXISTING', dates[0])
with self.assertRaises(MultipleSymbolsFound):
finder.lookup_symbol('EXISTING', None)
for i, date in enumerate(dates):
# Verify that we correctly resolve multiple symbols using
# the supplied date
result = finder.lookup_symbol('EXISTING', date)
self.assertEqual(result.symbol, 'EXISTING')
self.assertEqual(result.sid, i)
示例3: test_lookup_symbol_delimited
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_lookup_symbol_delimited(self):
as_of = pd.Timestamp("2013-01-01", tz="UTC")
frame = pd.DataFrame.from_records(
[
{
"sid": i,
"symbol": "TEST.%d" % i,
"company_name": "company%d" % i,
"start_date": as_of.value,
"end_date": as_of.value,
"exchange": uuid.uuid4().hex,
}
for i in range(3)
]
)
self.env.write_data(equities_df=frame)
finder = AssetFinder(self.env.engine)
asset_0, asset_1, asset_2 = (finder.retrieve_asset(i) for i in range(3))
# we do it twice to catch caching bugs
for i in range(2):
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol("TEST", as_of)
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol("TEST1", as_of)
# '@' is not a supported delimiter
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol("[email protected]", as_of)
# Adding an unnecessary fuzzy shouldn't matter.
for fuzzy_char in ["-", "/", "_", "."]:
self.assertEqual(asset_1, finder.lookup_symbol("TEST%s1" % fuzzy_char, as_of))
示例4: test_lookup_symbol_fuzzy
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_lookup_symbol_fuzzy(self):
as_of = pd.Timestamp('2013-01-01', tz='UTC')
frame = pd.DataFrame.from_records(
[
{
'sid': i,
'symbol': '[email protected]%d' % i,
'company_name': "company%d" % i,
'start_date': as_of.value,
'end_date': as_of.value,
'exchange': uuid.uuid4().hex,
'fuzzy': 'TEST%d' % i
}
for i in range(3)
]
)
self.env.write_data(equities_df=frame)
finder = AssetFinder(self.env.engine, fuzzy_char='@')
asset_0, asset_1, asset_2 = (
finder.retrieve_asset(i) for i in range(3)
)
for i in range(2): # we do it twice to test for caching bugs
self.assertIsNone(finder.lookup_symbol('test', as_of))
self.assertEqual(
asset_1,
finder.lookup_symbol('[email protected]', as_of)
)
# Adding an unnecessary fuzzy shouldn't matter.
self.assertEqual(
asset_1,
finder.lookup_symbol('[email protected]', as_of, fuzzy=True)
)
# Shouldn't find this with no fuzzy_str passed.
self.assertIsNone(finder.lookup_symbol('test1', as_of))
# Should find exact match.
self.assertEqual(
asset_1,
finder.lookup_symbol('test1', as_of, fuzzy=True),
)
示例5: test_sid_assignment
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_sid_assignment(self):
# This metadata does not contain SIDs
metadata = {'PLAY': {'symbol': 'PLAY'},
'MSFT': {'symbol': 'MSFT'}}
# Build a finder that is allowed to assign sids
finder = AssetFinder(metadata=metadata, allow_sid_assignment=True)
# Verify that Assets were built and different sids were assigned
play = finder.lookup_symbol('PLAY', datetime.now())
msft = finder.lookup_symbol('MSFT', datetime.now())
self.assertEqual('PLAY', play.symbol)
self.assertIsNotNone(play.sid)
self.assertNotEqual(play.sid, msft.sid)
示例6: test_sid_assignment
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_sid_assignment(self):
# This metadata does not contain SIDs
metadata = ["PLAY", "MSFT"]
today = normalize_date(pd.Timestamp("2015-07-09", tz="UTC"))
# Write data with sid assignment
self.env.write_data(equities_identifiers=metadata, allow_sid_assignment=True)
# Verify that Assets were built and different sids were assigned
finder = AssetFinder(self.env.engine)
play = finder.lookup_symbol("PLAY", today)
msft = finder.lookup_symbol("MSFT", today)
self.assertEqual("PLAY", play.symbol)
self.assertIsNotNone(play.sid)
self.assertNotEqual(play.sid, msft.sid)
示例7: test_sid_assignment
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_sid_assignment(self):
# This metadata does not contain SIDs
metadata = {'PLAY': {'symbol': 'PLAY'},
'MSFT': {'symbol': 'MSFT'}}
today = normalize_date(pd.Timestamp('2015-07-09', tz='UTC'))
# Build a finder that is allowed to assign sids
finder = AssetFinder(metadata=metadata,
allow_sid_assignment=True)
# Verify that Assets were built and different sids were assigned
play = finder.lookup_symbol('PLAY', today)
msft = finder.lookup_symbol('MSFT', today)
self.assertEqual('PLAY', play.symbol)
self.assertIsNotNone(play.sid)
self.assertNotEqual(play.sid, msft.sid)
示例8: test_lookup_symbol_delimited
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_lookup_symbol_delimited(self):
as_of = pd.Timestamp('2013-01-01', tz='UTC')
frame = pd.DataFrame.from_records(
[
{
'sid': i,
'symbol': 'TEST.%d' % i,
'company_name': "company%d" % i,
'start_date': as_of.value,
'end_date': as_of.value,
'exchange': uuid.uuid4().hex
}
for i in range(3)
]
)
self.env.write_data(equities_df=frame)
finder = AssetFinder(self.env.engine)
asset_0, asset_1, asset_2 = (
finder.retrieve_asset(i) for i in range(3)
)
# we do it twice to catch caching bugs
for i in range(2):
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('TEST', as_of)
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('TEST1', as_of)
# '@' is not a supported delimiter
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('[email protected]', as_of)
# Adding an unnecessary fuzzy shouldn't matter.
for fuzzy_char in ['-', '/', '_', '.']:
self.assertEqual(
asset_1,
finder.lookup_symbol('TEST%s1' % fuzzy_char, as_of)
)
示例9: test_lookup_symbol_fuzzy
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import lookup_symbol [as 别名]
def test_lookup_symbol_fuzzy(self):
as_of = pd.Timestamp('2013-01-01', tz='UTC')
frame = pd.DataFrame.from_records(
[
{
'sid': i,
'file_name': '[email protected]%d' % i,
'company_name': "company%d" % i,
'start_date_nano': as_of.value,
'end_date_nano': as_of.value,
'exchange': uuid.uuid4().hex,
}
for i in range(3)
]
)
finder = AssetFinder(frame)
asset_0, asset_1, asset_2 = (
finder.retrieve_asset(i) for i in range(3)
)
for i in range(2): # we do it twice to test for caching bugs
self.assertIsNone(finder.lookup_symbol('test', as_of))
self.assertEqual(
asset_1,
finder.lookup_symbol('[email protected]', as_of)
)
# Adding an unnecessary fuzzy shouldn't matter.
self.assertEqual(
asset_1,
finder.lookup_symbol('[email protected]', as_of, fuzzy='@')
)
# Shouldn't find this with no fuzzy_str passed.
self.assertIsNone(finder.lookup_symbol('test1', as_of))
# Shouldn't find this with an incorrect fuzzy_str.
self.assertIsNone(finder.lookup_symbol('test1', as_of, fuzzy='*'))
# Should find it with the correct fuzzy_str.
self.assertEqual(
asset_1,
finder.lookup_symbol('test1', as_of, fuzzy='@'),
)