mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-20 12:20:29 +08:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user