def test_get_datetime(self, name, tz): algo = dedent(""" import pandas as pd from zipline.api import get_datetime def initialize(context): context.tz = {tz} or 'UTC' context.first_bar = True def handle_data(context, data): if context.first_bar: dt = get_datetime({tz}) if dt.tz.zone != context.tz: raise ValueError("Mismatched Zone") elif dt.tz_convert("US/Eastern").hour != 9: raise ValueError("Mismatched Hour") elif dt.tz_convert("US/Eastern").minute != 31: raise ValueError("Mismatched Minute") context.first_bar = False """.format(tz=repr(tz))) start = to_utc('2014-01-02 9:31') end = to_utc('2014-01-03 9:31') source = RandomWalkSource( start=start, end=end, ) sim_params = factory.create_simulation_parameters( data_frequency='minute') algo = TradingAlgorithm(script=algo, sim_params=sim_params, identifiers=[1]) algo.run(source) self.assertFalse(algo.first_bar)
def test_get_datetime(self, name, tz): algo = dedent( """ import pandas as pd from zipline.api import get_datetime def initialize(context): context.tz = {tz} or 'UTC' context.first_bar = True def handle_data(context, data): if context.first_bar: dt = get_datetime({tz}) if dt.tz.zone != context.tz: raise ValueError("Mismatched Zone") elif dt.tz_convert("US/Eastern").hour != 9: raise ValueError("Mismatched Hour") elif dt.tz_convert("US/Eastern").minute != 31: raise ValueError("Mismatched Minute") context.first_bar = False """.format(tz=repr(tz)) ) start = to_utc('2014-01-02 9:31') end = to_utc('2014-01-03 9:31') source = RandomWalkSource( start=start, end=end, ) sim_params = factory.create_simulation_parameters( data_frequency='minute' ) algo = TradingAlgorithm( script=algo, sim_params=sim_params, identifiers=[1] ) algo.run(source) self.assertFalse(algo.first_bar)
""" if frequency == '1d': # First day of this test is July 3rd, which is a half day. if count < 210: return [np.nan, count] else: return [209, count] elif frequency == '1m': if count == 0: return [np.nan, count] else: return [count - 1, count] MIXED_FREQUENCY_MINUTES = _cases_env.market_minute_window( to_utc('2013-07-03 9:31AM'), 600, ) ONE_MINUTE_PRICE_ONLY_SPECS = [ HistorySpec(1, '1m', 'price', True, _cases_env, data_frequency='minute'), ] DAILY_OPEN_CLOSE_SPECS = [ HistorySpec(3, '1d', 'open_price', False, _cases_env, data_frequency='minute'), HistorySpec(3, '1d', 'close_price', False, _cases_env, data_frequency='minute'), ] ILLIQUID_PRICES_SPECS = [ HistorySpec(3, '1m', 'price', False, _cases_env, data_frequency='minute'), HistorySpec(5, '1m', 'price', True, _cases_env, data_frequency='minute'), ] MIXED_FREQUENCY_SPECS = [
""" if frequency == '1d': # First day of this test is July 3rd, which is a half day. if count < 210: return [np.nan, count] else: return [209, count] elif frequency == '1m': if count == 0: return [np.nan, count] else: return [count - 1, count] MIXED_FREQUENCY_MINUTES = _cases_env.market_minute_window( to_utc('2013-07-03 9:31AM'), 600, ) ONE_MINUTE_PRICE_ONLY_SPECS = [ HistorySpec(1, '1m', 'price', True, _cases_env, data_frequency='minute'), ] DAILY_OPEN_CLOSE_SPECS = [ HistorySpec(3, '1d', 'open_price', False, _cases_env, data_frequency='minute'), HistorySpec(3, '1d', 'close_price',