mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-17 11:25:55 +08:00
BUG: adjust benchmark events to match market hours
Previously benchmark events were emitted at 0:00 on the day the benchmark related to: in 'minute' emission mode this meant that the benchmarks were emitted before any intra-day trades were processed. See: https://github.com/quantopian/zipline/issues/241
This commit is contained in:
committed by
twiecki
parent
9feed61748
commit
45844bac31
@@ -159,3 +159,17 @@ class AlgorithmGeneratorTestCase(TestCase):
|
||||
gen = algo.get_generator()
|
||||
results = list(gen)
|
||||
self.assertEqual(results[-2]['progress'], 1.0)
|
||||
|
||||
def test_benchmark_times_match_market_close_for_minutely_data(self):
|
||||
"""
|
||||
Benchmark dates should be adjusted so that benchmark events are
|
||||
emitted at the end of each trading day when working with minutely
|
||||
data.
|
||||
Verification relies on the fact that there are no trades so
|
||||
algo.datetime should be equal to the last benchmark time.
|
||||
See https://github.com/quantopian/zipline/issues/241
|
||||
"""
|
||||
sim_params = factory.create_simulation_parameters(num_days=1)
|
||||
algo = TestAlgo(self, sim_params=sim_params, data_frequency='minute')
|
||||
algo.run(source=[])
|
||||
self.assertEqual(algo.datetime, sim_params.last_close)
|
||||
|
||||
@@ -227,8 +227,13 @@ class TradingAlgorithm(object):
|
||||
skipped.
|
||||
"""
|
||||
if self.benchmark_return_source is None:
|
||||
env = trading.environment
|
||||
if self.data_frequency == 'minute':
|
||||
update_time = lambda date: env.get_open_and_close(date)[1]
|
||||
else:
|
||||
update_time = lambda date: date
|
||||
benchmark_return_source = [
|
||||
Event({'dt': dt,
|
||||
Event({'dt': update_time(dt),
|
||||
'returns': ret,
|
||||
'type': zipline.protocol.DATASOURCE_TYPE.BENCHMARK,
|
||||
'source_id': 'benchmarks'})
|
||||
|
||||
Reference in New Issue
Block a user