stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
13.49k stars 4.26k forks source link

Zipline - chapter 4 - not working #65

Closed luisvelo closed 3 years ago

luisvelo commented 3 years ago

after creating 3.6 environment and doing data download from Quandl (that in the meantime I believe is closing) the line. It will be great if we are able to execute zipline examples from local, maybe with STOOQ or Yahoo data.

%%zipline --start 2015-1-1 --end 2018-1-1 --output single_factor.pickle

ends in this error NoBenchmark: Must specify either benchmark_sid or benchmark_returns. as of the below trace

%%zipline --start 2015-1-1 --end 2018-1-1 --output single_factor.pickle

Traceback (most recent call last):

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/utils/run_algo.py", line 216, in _run 'script': algotext,

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/algorithm.py", line 643, in run for perf in self.get_generator():

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/algorithm.py", line 619, in get_generator return self._create_generator(self.sim_params)

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/algorithm.py", line 580, in _create_generator benchmark_source = self._create_benchmark_source()

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/algorithm.py", line 543, in _create_benchmark_source raise NoBenchmark()

NoBenchmark: Must specify either benchmark_sid or benchmark_returns.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "", line 1, in get_ipython().run_cell_magic('zipline', '--start 2015-1-1 --end 2018-1-1 --output single_factor.pickle', '\n')

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2371, in run_cell_magic result = fn(*args, **kwargs)

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/main.py", line 348, in zipline_magic standalone_mode=False,

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx)

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params)

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs)

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func return f(get_current_context(), *args, **kwargs)

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/main.py", line 320, in run benchmark_spec=benchmark_spec,

File "/Users/luisvelo1/opt/anaconda3/envs/ml4t-zipline-mine/lib/python3.6/site-packages/zipline/utils/run_algo.py", line 227, in _run "Neither '--benchmark-symbol' nor '--benchmark-sid' was"

_RunAlgoError: No benchmark_spec was provided, and zipline.api.set_benchmark was not called in initialize.

luisvelo commented 3 years ago

https://github.com/stefan-jansen/machine-learning-for-trading/blob/master/04_alpha_factor_research/04_single_factor_zipline.ipynb this is the code link

stefan-jansen commented 3 years ago

Hi @luisvelo, are you running this using the patched Zipline version included in the Docker container or did you install Zipline on your own? The code will only work with the patched version; Chapter 8 has information on creating custom bundles for stooq etc; we also demonstrate how to use Backtrader to avoid some of the Zipline issues altogether.

I know that Quantopian is closing it's community platform since being acquired by Robinhood, but I was unaware that Quandl, which has been acquired by NASDAQ a while ago, will shut down - do you have a link for this news?

luisvelo commented 3 years ago

Hi Stefan

I did this to set the API KEY at the terminal and to execute

and this is how it fails

As said, I'm in Catalina, and I will prefer to go on the book chapter by chapter (now on chapter 4, on the zipline and then alphalens thing that should also use the Docker container because the source of data is 'single_factor.pickle').

Thanks a lot for your prompt reply and big thanks for the book, is excellent material Luis

On 3 Dec 2020, at 16:48, Stefan Jansen notifications@github.com wrote:

Hi @luisvelo https://github.com/luisvelo, are you running this using the patched Zipline version included in the Docker container or did you install Zipline on your own? The code will only work with the patched version; Chapter 8 https://github.com/stefan-jansen/machine-learning-for-trading/tree/master/08_ml4t_workflow/04_ml4t_workflow_with_zipline has information on creating custom bundles for stooq etc; we also demonstrate how to use Backtrader to avoid some of the Zipline issues altogether.

I know that Quantopian is closing it's community platform since being acquired by Robinhood, but I was unaware that Quandl, which has been acquired by NASDAQ a while ago, will shut down - do you have a link for this news?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stefan-jansen/machine-learning-for-trading/issues/65#issuecomment-738092103, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQXCVI4B5QCVDE7CRM5BTFLSS6XONANCNFSM4UMARM5A.

stefan-jansen commented 3 years ago

I can't see your code but I just reran zipline ingest in the docker container and it works fine. Note that you need to activate the ml4t-zipline environment first: conda activate ml4t-zipline, but you probably did that. If the download fails, I would doublecheck on how you are passing the API key.

luisvelo commented 3 years ago

issue closed, I was doing some steps wrong and then also a typo on the API key.