Closed RiccaDS closed 2 years ago
Hi,
First, you shouldn't directly import and use exchange_calendars
, it is "incompatible" with zipline-reloaded
(+1min delay in exchange opening).
I would import get_calendar
from zipline, this should ensure that you get the a calendar that is compatible.
Apparently, it "works" because you simply commented out a safety check that ensures that the trading calendar is the same.
Cheers,
M
@MBounouar hi, yes indeed commenting isn't a good solution. Using exchange_calendars
was the only solution I found to make the script go along a bit further. Before that I did try I importing get_calendar
but I now realize I was importing it from trading_calendar module out of zipline, and this was giving another error. So now following your suggestion I searched better for get_calendar:
from zipline.utils.calendar_utils import get_calendar
data_portal = DataPortal(bundle_data.asset_finder,
trading_calendar = get_calendar("XNYS"),
first_trading_day = start_aware,
equity_daily_reader = bundle_data.equity_minute_bar_reader,
adjustment_reader = bundle_data.adjustment_reader)
In this way it works although I still have some issues in my code. Thank you for the help!
Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment
Name Version Build Channel
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
alembic 1.7.7 pypi_0 pypi argon2-cffi 21.3.0 pyhd3eb1b0_0
argon2-cffi-bindings 21.2.0 py39h7f8727e_0
asttokens 2.0.5 pyhd3eb1b0_0
attrs 21.4.0 pyhd3eb1b0_0
backcall 0.2.0 pyhd3eb1b0_0
bcolz-zipline 1.2.4 pypi_0 pypi blas 1.0 mkl
bleach 4.1.0 pyhd3eb1b0_0
bottleneck 1.3.4 pypi_0 pypi brotli 1.0.9 he6710b0_2
ca-certificates 2022.3.29 h06a4308_0
certifi 2021.10.8 py39h06a4308_2
cffi 1.15.0 py39hd667e15_1
charset-normalizer 2.0.12 pypi_0 pypi click 8.0.4 pypi_0 pypi cycler 0.11.0 pyhd3eb1b0_0
dbus 1.13.18 hb2f20db_0
debugpy 1.5.1 py39h295c915_0
decorator 5.1.1 pyhd3eb1b0_0
defusedxml 0.7.1 pyhd3eb1b0_0
empyrical-reloaded 0.5.8 pypi_0 pypi entrypoints 0.3 py39h06a4308_0
exchange-calendars 3.3 pypi_0 pypi executing 0.8.3 pyhd3eb1b0_0
expat 2.4.4 h295c915_0
fontconfig 2.13.1 h6c09931_0
fonttools 4.25.0 pyhd3eb1b0_0
freetype 2.11.0 h70c0345_0
giflib 5.2.1 h7b6447c_0
glib 2.69.1 h4ff587b_1
greenlet 1.1.2 pypi_0 pypi gst-plugins-base 1.14.0 h8213a91_2
gstreamer 1.14.0 h28cd5cc_2
h5py 3.6.0 pypi_0 pypi icu 58.2 he6710b0_3
idna 3.3 pypi_0 pypi importlib-metadata 4.11.3 py39h06a4308_0
importlib_metadata 4.11.3 hd3eb1b0_0
intel-openmp 2021.4.0 h06a4308_3561
intervaltree 3.1.0 pypi_0 pypi ipykernel 6.9.1 py39h06a4308_0
ipympl 0.8.8 pypi_0 pypi ipython 8.2.0 py39h06a4308_0
ipython_genutils 0.2.0 pyhd3eb1b0_1
ipywidgets 7.6.5 pyhd3eb1b0_1
iso3166 2.0.2 pypi_0 pypi iso4217 1.8.20211001 pypi_0 pypi jedi 0.18.1 py39h06a4308_1
jinja2 3.0.3 pyhd3eb1b0_0
jpeg 9d h7f8727e_0
jsonschema 3.2.0 pyhd3eb1b0_2
jupyter 1.0.0 py39h06a4308_7
jupyter_client 7.1.2 pyhd3eb1b0_0
jupyter_console 6.4.3 pyhd3eb1b0_0
jupyter_core 4.9.2 py39h06a4308_0
jupyterlab_pygments 0.1.2 py_0
jupyterlab_widgets 1.0.0 pyhd3eb1b0_1
kiwisolver 1.3.2 py39h295c915_0
korean-lunar-calendar 0.2.1 pypi_0 pypi lcms2 2.12 h3be6417_0
ld_impl_linux-64 2.35.1 h7274673_9
libffi 3.3 he6710b0_2
libgcc-ng 9.3.0 h5101ec6_17
libgomp 9.3.0 h5101ec6_17
libpng 1.6.37 hbc83047_0
libsodium 1.0.18 h7b6447c_0
libstdcxx-ng 9.3.0 hd4cf53a_17
libtiff 4.2.0 h85742a9_0
libuuid 1.0.3 h7f8727e_2
libwebp 1.2.2 h55f646e_0
libwebp-base 1.2.2 h7f8727e_0
libxcb 1.14 h7b6447c_0
libxml2 2.9.12 h03d6c58_0
logbook 1.5.3 pypi_0 pypi lru-dict 1.1.7 pypi_0 pypi lxml 4.8.0 pypi_0 pypi lz4-c 1.9.3 h295c915_1
mako 1.2.0 pypi_0 pypi markupsafe 2.0.1 py39h27cfd23_0
matplotlib 3.5.1 py39h06a4308_0
matplotlib-base 3.5.1 py39ha18d171_1
matplotlib-inline 0.1.2 pyhd3eb1b0_2
mistune 0.8.4 py39h27cfd23_1000
mkl 2021.4.0 h06a4308_640
mkl-service 2.4.0 py39h7f8727e_0
mkl_fft 1.3.1 py39hd3c417c_0
mkl_random 1.2.2 py39h51133e4_0
multipledispatch 0.6.0 pypi_0 pypi multitasking 0.0.10 pypi_0 pypi munkres 1.1.4 py_0
nbclient 0.5.11 pyhd3eb1b0_0
nbconvert 6.3.0 py39h06a4308_0
nbformat 5.1.3 pyhd3eb1b0_0
ncurses 6.3 h7f8727e_2
nest-asyncio 1.5.1 pyhd3eb1b0_0
networkx 2.7.1 pypi_0 pypi notebook 6.4.8 py39h06a4308_0
numexpr 2.8.1 pypi_0 pypi numpy 1.22.3 pypi_0 pypi numpy-base 1.21.2 py39h79a1101_0
openssl 1.1.1n h7f8727e_0
packaging 21.3 pyhd3eb1b0_0
pandas 1.4.1 pypi_0 pypi pandas-datareader 0.10.0 pypi_0 pypi pandocfilters 1.5.0 pyhd3eb1b0_0
parso 0.8.3 pyhd3eb1b0_0
patsy 0.5.2 pypi_0 pypi pcre 8.45 h295c915_0
pexpect 4.8.0 pyhd3eb1b0_3
pickleshare 0.7.5 pyhd3eb1b0_1003
pillow 9.0.1 py39h22f2fdc_0
pip 21.2.4 py39h06a4308_0
prometheus_client 0.13.1 pyhd3eb1b0_0
prompt-toolkit 3.0.20 pyhd3eb1b0_0
prompt_toolkit 3.0.20 hd3eb1b0_0
ptyprocess 0.7.0 pyhd3eb1b0_2
pure_eval 0.2.2 pyhd3eb1b0_0
pycparser 2.21 pyhd3eb1b0_0
pygments 2.11.2 pyhd3eb1b0_0
pyluach 1.4.0 pypi_0 pypi pyparsing 3.0.4 pyhd3eb1b0_0
pyqt 5.9.2 py39h2531618_6
pyrsistent 0.18.0 py39heee7806_0
python 3.9.7 h12debd9_1
python-dateutil 2.8.2 pyhd3eb1b0_0
python-interface 1.6.1 pypi_0 pypi pytz 2021.3 pypi_0 pypi pyzmq 22.3.0 py39h295c915_2
qt 5.9.7 h5867ecd_1
qtconsole 5.3.0 pyhd3eb1b0_0
qtpy 2.0.1 pyhd3eb1b0_0
readline 8.1.2 h7f8727e_1
requests 2.27.1 pypi_0 pypi scipy 1.8.0 pypi_0 pypi send2trash 1.8.0 pyhd3eb1b0_1
setuptools 58.0.4 py39h06a4308_0
sip 4.19.13 py39h295c915_0
six 1.16.0 pyhd3eb1b0_1
sortedcontainers 2.4.0 pypi_0 pypi sqlalchemy 1.4.32 pypi_0 pypi sqlite 3.38.2 hc218d9a_0
stack_data 0.2.0 pyhd3eb1b0_0
statsmodels 0.13.2 pypi_0 pypi ta-lib 0.4.24 pypi_0 pypi tables 3.7.0 pypi_0 pypi terminado 0.13.1 py39h06a4308_0
testpath 0.5.0 pyhd3eb1b0_0
tk 8.6.11 h1ccaba5_0
toolz 0.11.2 pypi_0 pypi tornado 6.1 py39h27cfd23_0
trading-calendars 2.1.1 pypi_0 pypi traitlets 5.1.1 pyhd3eb1b0_0
typing-extensions 4.1.1 hd3eb1b0_0
typing_extensions 4.1.1 pyh06a4308_0
tzdata 2022a hda174b7_0
urllib3 1.26.8 pypi_0 pypi wcwidth 0.2.5 pyhd3eb1b0_0
webencodings 0.5.1 py39h06a4308_1
wheel 0.37.1 pyhd3eb1b0_0
widgetsnbextension 3.5.2 py39h06a4308_0
xz 5.2.5 h7b6447c_0
yfinance 0.1.70 pypi_0 pypi zeromq 4.3.4 h2531618_0
zipline-reloaded 2.2.0 pypi_0 pypi zipp 3.7.0 pyhd3eb1b0_0
zlib 1.2.11 h7f8727e_4
zstd 1.4.9 haebb681_0
Now that you know a little about me, let me tell you about the issue I am having:
When trying to create a data portal I receive the following error when passing the trading calendar to the the DataPortal function:
AssertionError: All readers must share target trading_calendar. Reader=<zipline.data.minute_bars.BcolzMinuteBarReader object at 0x7f2756788b50> for type=<class 'zipline.assets._assets.Equity'> uses calendar=<exchange_calendars.exchange_calendar_xnys.XNYSExchangeCalendar object at 0x7f27567513a0> which does not match the desired shared calendar=<exchange_calendars.exchange_calendar_xnys.XNYSExchangeCalendar object at 0x7f27567d1af0>
Here is how you can reproduce this issue on your machine:
Reproduction Steps
start_session = pd.Timestamp('2021-8-2', tz='utc') end_session = pd.Timestamp('2022-8-12', tz='utc')
bundles.register( 'il_mio_bundle', bundles.csvdir.csvdir_equities( ['minute'], '/home/riccardo/Scrivania/algo', ), calendar_name='XNYS', # US equities start_session=start_session, end_session=end_session )
start_def = '2021-08-02' end_def = '2021-08-12'
bundle_data = bundles.load('il_mio_bundle')
data_portal = DataPortal(bundle_data.asset_finder, trading_calendar = xcals.get_calendar('XNYS'), #THIS LINE GENERATES THE ERROR first_trading_day = pd.Timestamp(start_def, tz='UTC'), equity_daily_reader = bundle_data.equity_minute_bar_reader, adjustment_reader = bundle_data.adjustment_reader)
for t, r in self._readers.items(): assert trading_calendar == r.trading_calendar, ( "All readers must share target trading_calendar. " "Reader={0} for type={1} uses calendar={2} which does not " "match the desired shared calendar={3} ".format( r, t, r.trading_calendar, trading_calendar ) )