Skip to content

Commit

Permalink
MAINT: Makes RandomWalkSource emit midnight UTC events in daily mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
llllllllll committed Nov 19, 2014
1 parent f7b4d31 commit fcea785
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
21 changes: 9 additions & 12 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,11 @@ def handle_data(context, data):
np.testing.assert_almost_equal(recorded_ma,
159.76304468946876)

def test_history_container_constructed_at_runtime(self):
@parameterized.expand([
('daily',),
('minute',),
])
def test_history_container_constructed_at_runtime(self, data_freq):
algo_text = dedent(
"""\
from zipline.api import history
Expand All @@ -889,17 +893,17 @@ def handle_data(context, data):
period_start=start,
period_end=end,
capital_base=float("1.0e5"),
data_frequency='minute',
emission_rate='daily'
data_frequency=data_freq,
emission_rate=data_freq
)

test_algo = TradingAlgorithm(
script=algo_text,
data_frequency='minute',
data_frequency=data_freq,
sim_params=sim_params
)

source = RandomWalkSource(start=start, end=end)
source = RandomWalkSource(start=start, end=end, freq=data_freq)

self.assertIsNone(test_algo.history_container)
test_algo.run(source)
Expand All @@ -909,13 +913,6 @@ def handle_data(context, data):
)

container = test_algo.history_container
self.assertEqual(
container.buffer_panel.window_length,
Frequency.MAX_MINUTES['d'],
msg='HistoryContainer.buffer_panel was not large enough to service'
' the given HistorySpec',
)

self.assertEqual(
len(container.digest_panels),
1,
Expand Down
4 changes: 1 addition & 3 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,4 @@ def test_day(self):
self.assertLess(event.dt, end)
self.assertGreater(event.price, 0,
"price should never go negative.")
self.assertTrue(13 <= event.dt.hour <= 21,
"event.dt.hour == %i, not during market \
hours." % event.dt.hour)
self.assertEqual(event.dt.hour, 0)
4 changes: 3 additions & 1 deletion zipline/sources/simulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import numpy as np
from datetime import timedelta
import pandas as pd

from zipline.sources.data_source import DataSource
from zipline.utils import tradingcalendar as calendar_nyse
Expand Down Expand Up @@ -141,7 +142,8 @@ def raw_data_gen(self):
current_dt += timedelta(minutes=1)
elif self.freq == 'daily':
# Emit one signal per day at close
for event in self._gen_events(cur_prices, close_dt):
for event in self._gen_events(
cur_prices, pd.tslib.normalize_date(close_dt)):
yield event

@property
Expand Down

0 comments on commit fcea785

Please sign in to comment.