From 9688989eba202907ef805967e3ec6e4475e86a93 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 8 Jul 2015 14:35:10 -0400 Subject: [PATCH] MAINT: Use symbol lookup directly from algorithm. Instead of using the generic lookup, use the asset finder symbol method directly when `symbol` is used in an algorithm. --- tests/test_algorithm.py | 8 +++++++- zipline/algorithm.py | 8 +++----- zipline/test_algorithms.py | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/test_algorithm.py b/tests/test_algorithm.py index 6509c643..4a5db00d 100644 --- a/tests/test_algorithm.py +++ b/tests/test_algorithm.py @@ -597,13 +597,19 @@ class TestAlgoScript(TestCase): def test_api_get_environment(self): platform = 'zipline' + metadata = {0: {'symbol': 'TEST', + 'asset_type': 'equity'}} algo = TradingAlgorithm(script=api_get_environment_algo, + asset_metadata=metadata, platform=platform) algo.run(self.df) self.assertEqual(algo.environment, platform) def test_api_symbol(self): - algo = TradingAlgorithm(script=api_symbol_algo) + metadata = {0: {'symbol': 'TEST', + 'asset_type': 'equity'}} + algo = TradingAlgorithm(script=api_symbol_algo, + asset_metadata=metadata) algo.run(self.df) def test_fixed_slippage(self): diff --git a/zipline/algorithm.py b/zipline/algorithm.py index f6c7ff41..609373bd 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -662,11 +662,9 @@ class TradingAlgorithm(object): Default symbol lookup for any source that directly maps the symbol to the Asset (e.g. yahoo finance). """ - asset, _ = self.asset_finder.lookup_generic( - asset_convertible_or_iterable=symbol_str, - as_of_date=self.datetime, - ) - return asset + return self.asset_finder.lookup_symbol_resolve_multiple( + symbol_str, + as_of_date=self.datetime) @api_method def symbols(self, *args): diff --git a/zipline/test_algorithms.py b/zipline/test_algorithms.py index 7942d32c..496c3739 100644 --- a/zipline/test_algorithms.py +++ b/zipline/test_algorithms.py @@ -1003,7 +1003,7 @@ from zipline.api import get_environment, order, symbol def initialize(context): context.environment = get_environment() -handle_data = lambda context, data: order(symbol(0), 1) +handle_data = lambda context, data: order(symbol('TEST'), 1) """ api_symbol_algo = """ @@ -1014,7 +1014,7 @@ def initialize(context): pass def handle_data(context, data): - order(symbol(0), 1) + order(symbol('TEST'), 1) """ call_order_in_init = """