mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-15 11:22:18 +08:00
Merge pull request #372 from quantopian/moved-perf-tracker-assignment
BUG: Put initialization of perf_tracker back in __init__
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):
|
||||
|
||||
@@ -157,9 +157,7 @@ class TradingAlgorithm(object):
|
||||
self.sim_params = create_simulation_parameters(
|
||||
capital_base=self.capital_base
|
||||
)
|
||||
|
||||
# perf_tacker gets instantiated in ._create_generator()
|
||||
self.perf_tracker = None
|
||||
self.perf_tracker = PerformanceTracker(self.sim_params)
|
||||
|
||||
self.blotter = kwargs.pop('blotter', None)
|
||||
if not self.blotter:
|
||||
@@ -318,8 +316,8 @@ class TradingAlgorithm(object):
|
||||
skipped.
|
||||
"""
|
||||
# Instantiate perf_tracker
|
||||
if self.perf_tracker is None:
|
||||
self.perf_tracker = PerformanceTracker(sim_params)
|
||||
self.perf_tracker = PerformanceTracker(sim_params)
|
||||
self.portfolio_needs_update = True
|
||||
|
||||
self.data_gen = self._create_data_generator(source_filter, sim_params)
|
||||
|
||||
|
||||
@@ -961,6 +961,15 @@ def handle_data(context, data):
|
||||
pass
|
||||
"""
|
||||
|
||||
access_portfolio_in_init = """
|
||||
def initialize(context):
|
||||
var = context.portfolio.cash
|
||||
pass
|
||||
|
||||
def handle_data(context, data):
|
||||
pass
|
||||
"""
|
||||
|
||||
call_all_order_methods = """
|
||||
from zipline.api import (order,
|
||||
order_value,
|
||||
|
||||
Reference in New Issue
Block a user