mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-29 16:46:59 +08:00
BUG: Fix updating of trading_days_total in minute.
In the batch_transform we were incrementing the trading_days counter if there is a new day event. Thus with a window_length of 1 and daily bars you will update the batch_transform on the first day which is correct. But with minutes you update with the first minute bar of the day which is not correct. This is fixed by calculating the market_close explicity and seeing whether the event.dt is on or past it. I also added a unittest to test the correct behavior of this.
This commit is contained in:
committed by
Eddie Hebert
parent
4a991c062b
commit
3ea8ac8da2
@@ -147,6 +147,16 @@ class TestBatchTransformMinutely(TestCase):
|
||||
for bt in algo.history[wl:]:
|
||||
self.assertEqual(len(bt), wl)
|
||||
|
||||
def test_window_length(self):
|
||||
algo = BatchTransformAlgorithmMinute(sim_params=self.sim_params,
|
||||
window_length=1, refresh_period=0)
|
||||
algo.run(self.source)
|
||||
wl = int(algo.window_length * 6.5 * 60)
|
||||
np.testing.assert_array_equal(algo.history[:(wl - 1)],
|
||||
[None] * (wl - 1))
|
||||
for bt in algo.history[wl:]:
|
||||
self.assertEqual(len(bt), wl)
|
||||
|
||||
|
||||
class TestBatchTransform(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -456,10 +456,15 @@ class BatchTransform(object):
|
||||
columns=sids))
|
||||
|
||||
# update trading day counters
|
||||
if self.last_dt.day != event.dt.day:
|
||||
self.last_dt = event.dt
|
||||
_, mkt_close = trading.environment.get_open_and_close(event.dt)
|
||||
if self.bars == 'daily':
|
||||
# Daily bars have their dt set to midnight.
|
||||
mkt_close = mkt_close.replace(hour=0, minute=0, second=0)
|
||||
if event.dt >= mkt_close:
|
||||
self.trading_days_total += 1
|
||||
|
||||
self.last_dt = event.dt
|
||||
|
||||
if self.trading_days_total >= self.window_length:
|
||||
self.full = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user