From 68e44353cea0a1006ab9fbdd6a4c8ada684dc229 Mon Sep 17 00:00:00 2001 From: Joe Jevnik Date: Tue, 18 Nov 2014 15:23:10 -0500 Subject: [PATCH] MAINT: Make RandomWalkSource accept the standard daily instead of day for the frequency --- tests/test_sources.py | 2 +- zipline/sources/simulated.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_sources.py b/tests/test_sources.py index 506887e1..a3590cfa 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -113,7 +113,7 @@ class TestRandomWalkSource(TestCase): end = pd.Timestamp('1992-01-01', tz='UTC') source = RandomWalkSource(start_prices=start_prices, calendar=calendar_nyse, start=start, - end=end, freq='day') + end=end, freq='daily') self.assertIsInstance(source.start, pd.lib.Timestamp) self.assertIsInstance(source.end, pd.lib.Timestamp) diff --git a/zipline/sources/simulated.py b/zipline/sources/simulated.py index 5e348d97..f7b6ec49 100644 --- a/zipline/sources/simulated.py +++ b/zipline/sources/simulated.py @@ -31,6 +31,8 @@ class RandomWalkSource(DataSource): user-defined frequencies (e.g. minutely). """ + VALID_FREQS = frozenset(('daily', 'minute')) + def __init__(self, start_prices=None, freq='minute', start=None, end=None, calendar=calendar_nyse): """ @@ -40,7 +42,7 @@ class RandomWalkSource(DataSource): Default: {0: 100, 1: 500} freq : str Emits events according to freq. - Can be 'day' or 'minute' + Can be 'daily' or 'minute' start : datetime Start dt to emit events. end : datetime @@ -61,6 +63,9 @@ class RandomWalkSource(DataSource): self.arg_string = hash_args(start_prices, freq, start, end, calendar.__name__) + if freq not in self.VALID_FREQS: + raise ValueError('%s not in %s' % (freq, self.VALID_FREQS)) + self.freq = freq if start_prices is None: self.start_prices = {0: 100, @@ -134,7 +139,7 @@ class RandomWalkSource(DataSource): for event in self._gen_events(cur_prices, current_dt): yield event current_dt += timedelta(minutes=1) - elif self.freq == 'day': + elif self.freq == 'daily': # Emit one signal per day at close for event in self._gen_events(cur_prices, close_dt): yield event