BUG: Put initialization of perf_tracker back in __init__

The initialization of perf_tracker had been moved from __init__
in TradingAlgorithm to _create_generator. This caused perf_tracker
to not be ready when portfolio requested it. portfolio was consequently
not ready for access in init. portfolio can now be accessed in init
again, assuming valid sim_params are passed. Otherwise it will be
available in handle_data() after _create_generator() is called.
This commit is contained in:
Delaney Granizo-Mackenzie
2014-07-21 12:17:07 -04:00
parent eae41b8e7a
commit 97c88c3c30
3 changed files with 31 additions and 5 deletions
+19
View File
@@ -34,6 +34,7 @@ from zipline.errors import (
TradingControlViolation,
)
from zipline.test_algorithms import (
access_portfolio_in_init,
AmbitiousStopLimitAlgorithm,
EmptyPositionsAlgorithm,
InvalidOrderAlgorithm,
@@ -617,6 +618,24 @@ def handle_data(context, data):
)
set_algo_instance(test_algo)
def test_portfolio_in_init(self):
"""
Test that accessing portfolio in init doesn't break.
"""
test_algo = TradingAlgorithm(
script=access_portfolio_in_init,
sim_params=self.sim_params,
)
set_algo_instance(test_algo)
self.zipline_test_config['algorithm'] = test_algo
self.zipline_test_config['trade_count'] = 1
zipline = simfactory.create_test_zipline(
**self.zipline_test_config)
output, _ = drain_zipline(self, zipline)
class TestHistory(TestCase):
def test_history(self):