def test_get_value_at_midnight(self): # make sure that if we try to get a minute price at a non-market # minute, we use the previous market close's timestamp day = self.equity_minute_bar_days[1] eight_fortyfive_am_eastern = \ pd.Timestamp("{0}-{1}-{2} 8:45".format( day.year, day.month, day.day), tz='US/Eastern' ) bar_data = self.create_bardata(lambda: day, ) bar_data2 = self.create_bardata(lambda: eight_fortyfive_am_eastern, ) with handle_non_market_minutes(bar_data), \ handle_non_market_minutes(bar_data2): for bd in [bar_data, bar_data2]: for field in ["close", "price"]: self.assertEqual(390, bd.current(self.ASSET1, field)) # make sure that if the asset didn't trade at the previous # close, we properly ffill (or not ffill) self.assertEqual( 350, bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "price")) self.assertTrue( np.isnan( bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "high"))) self.assertEqual( 0, bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "volume"))
def test_overnight_adjustments(self): # verify there is a split for SPLIT_ASSET splits = self.adjustment_reader.get_adjustments_for_sid( "splits", self.SPLIT_ASSET.sid) self.assertEqual(1, len(splits)) split = splits[0] self.assertEqual(split[0], pd.Timestamp("2016-01-06", tz='UTC')) # Current day is 1/06/16 day = self.equity_daily_bar_days[1] eight_fortyfive_am_eastern = \ pd.Timestamp("{0}-{1}-{2} 8:45".format( day.year, day.month, day.day), tz='US/Eastern' ) bar_data = self.create_bardata(lambda: eight_fortyfive_am_eastern, ) expected = { 'open': 391 / 2.0, 'high': 392 / 2.0, 'low': 389 / 2.0, 'close': 390 / 2.0, 'volume': 39000 * 2.0, 'price': 390 / 2.0, } with handle_non_market_minutes(bar_data): for field in OHLCP + ['volume']: value = bar_data.current(self.SPLIT_ASSET, field) # Assert the price is adjusted for the overnight split self.assertEqual(value, expected[field])
def test_is_stale_during_non_market_hours(self): bar_data = self.create_bardata( lambda: self.equity_minute_bar_days[1], ) with handle_non_market_minutes(bar_data): self.assertTrue(bar_data.is_stale(self.HILARIOUSLY_ILLIQUID_ASSET))
def test_get_value_at_midnight(self): # make sure that if we try to get a minute price at a non-market # minute, we use the previous market close's timestamp day = self.equity_minute_bar_days[1] eight_fortyfive_am_eastern = \ pd.Timestamp("{0}-{1}-{2} 8:45".format( day.year, day.month, day.day), tz='US/Eastern' ) bar_data = self.create_bardata( lambda: day, ) bar_data2 = self.create_bardata( lambda: eight_fortyfive_am_eastern, ) with handle_non_market_minutes(bar_data), \ handle_non_market_minutes(bar_data2): for bd in [bar_data, bar_data2]: for field in ["close", "price"]: self.assertEqual( 390, bd.current(self.ASSET1, field) ) # make sure that if the asset didn't trade at the previous # close, we properly ffill (or not ffill) self.assertEqual( 350, bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "price") ) self.assertTrue( np.isnan(bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "high")) ) self.assertEqual( 0, bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "volume") )
def test_overnight_adjustments(self): # verify there is a split for SPLIT_ASSET splits = self.adjustment_reader.get_adjustments_for_sid( "splits", self.SPLIT_ASSET.sid ) self.assertEqual(1, len(splits)) split = splits[0] self.assertEqual( split[0], pd.Timestamp("2016-01-06", tz='UTC') ) # Current day is 1/06/16 day = self.equity_daily_bar_days[1] eight_fortyfive_am_eastern = \ pd.Timestamp("{0}-{1}-{2} 8:45".format( day.year, day.month, day.day), tz='US/Eastern' ) bar_data = self.create_bardata( lambda: eight_fortyfive_am_eastern, ) expected = { 'open': 391 / 2.0, 'high': 392 / 2.0, 'low': 389 / 2.0, 'close': 390 / 2.0, 'volume': 39000 * 2.0, 'price': 390 / 2.0, } with handle_non_market_minutes(bar_data): for field in OHLCP + ['volume']: value = bar_data.current(self.SPLIT_ASSET, field) # Assert the price is adjusted for the overnight split self.assertEqual(value, expected[field])