mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 13:17:43 +08:00
10885e1b77
There were sevaral places you could supply sim_params in TradingAlgorithm (__init__, run). This got confusing as its not clear who updated what and which one was the correct one to use at each time. Then there were to ways to define data_frequency, one in __init__() and one in the sim_params which also added code complexity. This refactor makes it explicit that sim_params are to be passed to __init__() only. Moreover, data_frequency is only stored in sim_params. For backwards compatibility, it can still be supplied separately but will link to the one in sim_params. For example, you could create new sim params via: sim_params = create_simulation_parameters(data_frequency='minute') algo = MyAlgo(sim_params) algo.run(data) In addition, perf_tracker only gets initialized in one place: _create_generator() which should also make the various ways of running an algorithm more deterministic. This also fixes a bug with SimulationParameters where you could not change the period_start. Unfortunately, the current implementation still requieres an implicit call to update the internal variables.
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
#
|
|
# Copyright 2014 Quantopian, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from unittest import TestCase
|
|
from zipline.test_algorithms import NoopAlgorithm
|
|
from zipline.utils import factory
|
|
|
|
|
|
class TestTradeSimulation(TestCase):
|
|
|
|
def test_minutely_emissions_generate_performance_stats_for_last_day(self):
|
|
params = factory.create_simulation_parameters(num_days=1,
|
|
data_frequency='minute',
|
|
emission_rate='minute')
|
|
algo = NoopAlgorithm(sim_params=params)
|
|
algo.run(source=[])
|
|
self.assertEqual(algo.perf_tracker.day_count, 1.0)
|