PricingDataNotLoadedError: Missing data for {exchange} {symbols} in date range [{start_dt} - {end_dt}]
Dear Catalyst Maintainers,
Before I tell you about my issue, let me describe my environment:
Environment
- Operating System: Windows 7 Home Premium (64-bit)
- Python Version: 3.6.4
- How did you install Catalyst: conda + yml
- Python packages: aiodns aiohttp alabaster alembic asn1crypto astroid async-timeout attrdict attrs babel backcall bcolz blas bleach boto3 botocore Bottleneck ca-certificates cchardet ccxt certifi cffi chardet chardet click cloudpickle colorama contextlib2 cryptography cycler cyordereddict Cython cytoolz decorator decorator docutils docutils empyrical enigma-catalyst entrypoints eth-abi eth-account eth-hash eth-keyfile eth-keys eth-rlp eth-utils freetype hexbytes html5lib icc_rt icu idna idna idna-ssl imagesize intel-openmp intervaltree ipykernel ipython ipython_genutils isort jedi jinja2 jmespath jpeg jsonschema jupyter_client jupyter_core keyring kiwisolver lazy-object-proxy libpng libsodium Logbook lru-dict lxml Mako MarkupSafe markupsafe matplotlib mccabe mistune mkl multidict multipledispatch nbconvert nbformat networkx numexpr numpy numpydoc openssl packaging pandas pandas-datareader pandoc pandocfilters parsimonious parso patsy pickleshare pip prompt_toolkit psutil pycares pycodestyle pycparser pycryptodome pyflakes pygments pylint pyopenssl pyparsing pypiwin32 pyqt pysha3 pysocks python python-dateutil python-editor pytz pytz pywin32 pywin32 pyzmq qt qtawesome qtconsole qtpy redo requests requests requests-file requests-ftp requests-toolbelt rlp rope s3transfer scipy setuptools setuptools simplegeneric sip six snowballstemmer sortedcontainers sphinx sphinxcontrib sphinxcontrib-websupport spyder spyder-kernels SQLAlchemy sqlite statsmodels tables testpath tk toolz tornado traitlets typed-ast urllib3 urllib3 vc virtualenv vs2015_runtime wcwidth web3 webencodings websockets wheel win_inet_pton wincertstore wrapt wrapt xlrd xz yarl zeromq zlib
Now that you know a little about me, let me tell you about the issue I am having:
Description of Issue
Everything was working fine and as expected until I ingested the polo universe of cryptos (catalyst ingest-exchange -x poloniex -f daily -s 2018-1-1) now no matter what I run I receive this error :
Traceback (most recent call last):
File "
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace)
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Alex/Documents/testing29_9.py", line 154, in
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\utils\run_algo.py", line 596, in run_algorithm stats_output=stats_output
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\utils\run_algo.py", line 358, in _run overwrite_sim_params=False,
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_algorithm.py", line 403, in run data, overwrite_sim_params
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_algorithm.py", line 360, in run data, overwrite_sim_params
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\algorithm.py", line 725, in run for perf in self.get_generator():
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\gens\tradesimulation.py", line 224, in transform for capital_change_packet in every_bar(dt):
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\gens\tradesimulation.py", line 137, in every_bar handle_data(algo, current_data, dt_to_use)
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\utils\events.py", line 216, in handle_data dt,
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\utils\events.py", line 235, in handle_data self.callback(context, data)
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_algorithm.py", line 381, in handle_data super(ExchangeTradingAlgorithmBacktest, self).handle_data(data)
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\algorithm.py", line 474, in handle_data self._handle_data(self, data)
File "C:/Users/Alex/Documents/testing29_9.py", line 50, in handle_data frequency = '1T')
File "catalyst_protocol.pyx", line 120, in catalyst._protocol.check_parameters.call.assert_keywords_and_call
File "catalyst_protocol.pyx", line 633, in catalyst._protocol.BarData.history
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_data_portal.py", line 97, in get_history_window ffill))
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\redo_init_.py", line 162, in retry return action(*args, **kwargs)
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_data_portal.py", line 71, in _get_history_window ffill)
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_data_portal.py", line 325, in get_exchange_history_window algo_end_dt=self._last_available_session,
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_bundle.py", line 899, in get_history_window_series_and_load data_frequency=data_frequency,
File "C:\Users\Alex\Anaconda3\envs\catalyst\lib\site-packages\catalyst\exchange\exchange_bundle.py", line 987, in get_history_window_series end_dt=end_dt
PricingDataNotLoadedError: Missing data for {exchange} {symbols} in date range [{start_dt} - {end_dt}]
Please run: catalyst ingest-exchange -x {exchange} -f {data_frequency} -i {symbol_list}. See catalyst documentation for details.
I've tried it with a simple script printing ltc_btc and bcn_btc which was working prior to ingesting and also with an adapted simple_universe (to work with daily data) with varying date ranges and look-back periods which returns nothing (instead of printing daily prices for the date-range specified) as if the data isn't there.
I have tried cleaning the exchange data with: catalyst clean-exchange -x poloniex -f daily as well as removing the catalyst environment and creating it afresh.
Here is how you can reproduce this issue on your machine:
Reproduction Steps
- catalyst ingest-exchange -x poloniex -f daily
2.
` import pandas as pd
from datetime import datetime from catalyst.api import order, record, symbol, symbols, order_target_percent from catalyst.utils.run_algo import run_algorithm
#for statistical tests import statsmodels.tsa.stattools as ts import statsmodels.api as sm import matplotlib.pyplot as plt #from pykalman import KalmanFilter import numpy as np from numpy import log, polyfit, sqrt, std, subtract
def initialize(context):
context.asset = symbol('ltc_btc')
context.asset2 = symbol('bcn_btc')
context.set_commission(maker=0.01, taker=0.02)
context.set_slippage(slippage=0.001)
#context.entryZscore = 2
#context.exitZscore = 0
def handle_data(context, data):
context.i = 0
hist1 = data.history(context.asset,
'price',
bar_count=30,
frequency = '1T')
hist2 = data.history(context.asset2,
'price',
bar_count=30,
frequency = '1T')
#context.ltcbtchist = ltcbtchist
#ltcbtc = data.current(context.asset, 'price')
#bcnbtc = data.current(context.asset2, 'price')
#print('Data: {}'.format(data.current_dt))
#print('LTCBTC: {}'.format(ltcbtc))
#print('BCNBTC: {}'.format(bcnbtc))
#%%
#Spread
est = sm.OLS(hist2, hist1)
est = est.fit()
hr = -est.params[0]
context.spread = hist2 + (hist1 * hr)
#%%
#Halflife spread = context.spread
spread_lag = spread.shift(1)
spread_lag.iloc[0] = spread_lag.iloc[1]
spread_ret = spread - spread_lag
spread_ret.iloc[0] = spread_ret.iloc[1]
spread_lag2 = sm.add_constant(spread_lag)
model = sm.OLS(spread_ret,spread_lag2)
res = model.fit()
context.halflife = int(round(-np.log(2) / res.params[1],0))
if context.halflife <= 0:
context.halflife = 1
#%%
#Zscore
context.meanspread=spread.rolling(window=context.halflife).mean()
context.stdspread = spread.rolling(window=context.halflife).std()
context.zscore = (spread-context.meanspread)/context.stdspread
#%%
#context.i += 1
#if context.i < context.halflife: #return
if context.zscore[-1] >= 0.5 and context.asset not in context.portfolio.positions:
order_target_percent(context.asset, -1)
order_target_percent(context.asset2, 1)
elif context.zscore[-1] <= -0.5 and context.asset2 not in context.portfolio.positions:
order_target_percent(context.asset, 1)
order_target_percent(context.asset2, -1)
def analyze(context, perf):
ax1 = plt.subplot()
perf.portfolio_value.plot(ax=ax1)
#print(context.ltcbtchist)
#print(context.spread.shape)
#print(context.halflife)
print(context.zscore)
#print(context.meanspread)
#print(context.stdspread)
#print(context.spreadlength)
results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, live=False, start=pd.to_datetime('2018-8-1', utc=True), end=pd.to_datetime('2018-9-1', utc=True), exchange_name='poloniex', data_frequency='daily', quote_currency ='btc', capital_base=10000 )` 3. ...
What steps have you taken to resolve this already?
removing data bundles and re-ingesting, removing catalyst environment and re-creating ...
Anything else?
...
Thanks for taking the time to read this! Everything was running smoothly until idontknowhwhat and now it's refusing to play nice, Alex
Minute data seems to be working fine - just the daily seems to be causing the error for me
Hi @flipflop4 ,
If you have cleared the entire exchange data and ingested only the daily data afterwards, you will not be able to run this algorithm successfully because it requires the minute pricing data.
In the history function you are trying to read minute data by specifying the IT frequency.
So in order to make your algorithm work, you will need to ingest the minute data as well.
Lena
@flipflop4 I am closing this, feel free to reopen if you feel otherwise.