def test_equity_calendar_domain(self): # test non-default time self._test_equity_calendar_domain( EquityCalendarDomain( CountryCode.UNITED_STATES, 'XNYS', data_query_offset=-datetime.timedelta(hours=2, minutes=30), ), datetime.time(7, 0), ) # test offset that changes the date self._test_equity_calendar_domain( EquityCalendarDomain( CountryCode.UNITED_STATES, 'XNYS', data_query_offset=-datetime.timedelta(hours=10), ), datetime.time(23, 30), expected_cutoff_date_offset=-1, ) # test an offset that moves us back by more than one day self._test_equity_calendar_domain( EquityCalendarDomain( CountryCode.UNITED_STATES, 'XNYS', data_query_offset=-datetime.timedelta(hours=24 * 6 + 10), ), datetime.time(23, 30), expected_cutoff_date_offset=-7, )
def test_equity_calendar_domain(self): # test non-default time self._test_equity_calendar_domain( EquityCalendarDomain( CountryCode.UNITED_STATES, "XNYS", data_query_offset=-np.timedelta64(2 * 60 + 30, "m"), ), datetime.time(7, 0), ) # test offset that changes the date self._test_equity_calendar_domain( EquityCalendarDomain( CountryCode.UNITED_STATES, "XNYS", data_query_offset=-np.timedelta64(10, "h"), ), datetime.time(23, 30), expected_cutoff_date_offset=-1, ) # test an offset that moves us back by more than one day self._test_equity_calendar_domain( EquityCalendarDomain( CountryCode.UNITED_STATES, "XNYS", data_query_offset=-np.timedelta64(24 * 6 + 10, "h"), ), datetime.time(23, 30), expected_cutoff_date_offset=-7, )
from zipline.pipeline.domain import EquityCalendarDomain, CountryCode AShare_EQUITIES = EquityCalendarDomain(CountryCode.CHINA, 'AShare')
from zipline.pipeline.loaders.equity_pricing_loader import USEquityPricingLoader from zipline.pipeline.domain import EquityCalendarDomain from zipline.pipeline.data import USEquityPricing import pandas as pd import numpy as np from sharadar.pipeline.engine import symbols, make_pipeline_engine, load_sharadar_bundle bundle = load_sharadar_bundle() loader = USEquityPricingLoader.without_fx(bundle.equity_daily_bar_reader, bundle.adjustment_reader) domain = EquityCalendarDomain('US', 'XNYS') columns = [USEquityPricing.close] # AAPL sid 199059 sids = pd.Int64Index([199059]) mask = None start = pd.to_datetime('2020-08-26', utc=True) end = pd.to_datetime('2020-09-02', utc=True) trading_calendar = bundle.equity_daily_bar_reader.trading_calendar dates = trading_calendar.sessions_in_range(start, end) array = loader.load_adjusted_array(domain, columns, dates, sids, mask) adjusted_array = list(array.values())[0] print(adjusted_array.data) print(adjusted_array.adjustments) print(adjusted_array.data[3])