Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass analyze #819

Merged
merged 5 commits into from Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/test_algorithm.py
Expand Up @@ -1891,3 +1891,34 @@ def check_algo_positions(self, results, expected_positions):
actual_position, expected_positions[i],
"position for day={0} not equal, actual={1}, expected={2}".
format(i, actual_position, expected_positions[i]))


class TestTradingAlgorithm(TestCase):
def setUp(self):
self.env = TradingEnvironment()
self.days = self.env.trading_days[:4]
self.panel = pd.Panel({1: pd.DataFrame({
'price': [1, 1, 2, 4], 'volume': [1e9, 1e9, 1e9, 0],
'type': [DATASOURCE_TYPE.TRADE,
DATASOURCE_TYPE.TRADE,
DATASOURCE_TYPE.TRADE,
DATASOURCE_TYPE.CLOSE_POSITION]},
index=self.days)
})

def test_analyze_called(self):
self.perf_ref = None

def initialize(context):
pass

def handle_data(context, data):
pass

def analyze(context, perf):
self.perf_ref = perf

algo = TradingAlgorithm(initialize=initialize, handle_data=handle_data,
analyze=analyze)
results = algo.run(self.panel)
self.assertIs(results, self.perf_ref)
1 change: 1 addition & 0 deletions zipline/algorithm.py
Expand Up @@ -297,6 +297,7 @@ def __init__(self, *args, **kwargs):
self._handle_data = kwargs.pop('handle_data')
self._before_trading_start = kwargs.pop('before_trading_start',
None)
self._analyze = kwargs.pop('analyze', None)

self.event_manager.add_event(
zipline.utils.events.Event(
Expand Down