most examples don't work outside quantopian env
Hi guys,
Please update http://www.zipline.io/ because dual_moving_avg.py doesn't exist, its dual_moving_average.py. This strategy work perfectly in quantopian environment but not with zipline CLI. I suspect the ichart.finance.yahoo path to be broken (see details at the end).
The only example that works or don't crash is buyapple.
dual_ema_talib.py -> ImportError: No module named talib
pairtrade.py-> ValueError: You must define a handle_data function.
olmar.py-> AttributeError: 'TradingAlgorithm' object has no attribute 'symbol'
buyapple_analyze.py-> ValueError: You must define a handle_data function.
Thanks,
Fraka6
zipline.version Out[39]: '0.7.0'
python scripts/run_algo.py -f zipline/examples/dual_moving_average.py --symbols AAPL --start 2011-1-1 --end 2012-1-1 -o dma.pickle
...
[2015-07-30 04:14:04.415502] WARNING: Loader: No benchmark data found for date range.
start_date=2015-07-30 00:00:00+00:00, end_date=2015-07-30 04:14:04.295081, url=http://ichart.finance.yahoo.com/table.csv?a=6&c=2015&b=30&e=30&d=6&g=d&f=2015&s=%5EGSPC
[2015-07-30 04:14:24.025207] INFO: Performance: Simulated 252 trading days out of 252.
[2015-07-30 04:14:24.025510] INFO: Performance: first open: 2011-01-03 14:31:00+00:00
[2015-07-30 04:14:24.025611] INFO: Performance: last close: 2011-12-30 21:00:00+00:00
Traceback (most recent call last):
...
File "scripts/run_algo.py", line 25, in
I'm having the same problem, getting the same error when trying to run dual_moving_average.py.
Has this issue been fixed?
Can you try with a more recent version?
pip install -U git+https://github.com/quantopian/zipline
I did tried it at the time with the latest version and just retried after a pull and I get the same error.
Self-assigning to investigate.
I think this is the same issue as https://github.com/quantopian/zipline/issues/650.
I also just ran into this, it seems that order() is currently broken in zipline.
OK, this actually seems unrelated to order(). For some reason, the perf dataframe passed to analyze() does not contain a column for the record()ed variables.
Assigning to @StewartDouglas Stewart - I believe that Thomas is right and the issue may be related to my recent refactor of the perf packet generation in the trade simulation. We'll discuss in more detail off-line.
I believe this may be the culprit commit: https://github.com/quantopian/zipline/commit/8d5bfd3c917a8bd0c80fd8237c58296eb1f84728
This one is also possibly the culprit, but I doubt it: https://github.com/quantopian/zipline/commit/16ab46b69c888a844481c08fa865a10923489c54
The reason that the perf dataframe passed to analyze() does not contain the record()ed variables is that the algorithm skips the first 300 days:
if context.i < 300:
return
The algorithm works correctly when we run it over 300 days or more, for example:
PYTHONPATH=. python scripts/run_algo.py -f zipline/examples/dual_moving_average.py --symbols AAPL --start 2011-1-1 --end 2012-3-12
This suggests to me that analyze() should be modified so that it does not fail in the days < 300 case.
It's always the simple things... Thanks for figuring this out @StewartDouglas. Not sure how we can make this more obvious. The easiest for us would probably be to check in analyze whether AAPL is present and raise a helpful error message if not.
@fraka6 I have opened a PR which should address the issue you were experiencing with dual_moving_average.py, thank you for bringing it to our attention.
Regarding the other algorithms you mentioned:
- buyapple_analyze.py is not itself an algorithm but is a utility file which helps us to output information. I have moved it to a new directory,
examples/utils, to make clearer the fact that it is not an algorithm. - dual_ema_talib.py, olmar.py and pairtrade.py can all be run from the command line directly (as opposed to using scripts/run_algo.py):
PYTHONPATH=. python zipline/examples/<algo>.py
Please do let us know if you're still have trouble with dual_ema_talib.py.
We have now removed the _analyze.py files entirely, and instead moved the analyze() methods into the algo files themselves. You can see our discussion on this and other issues here: https://github.com/quantopian/zipline/pull/697. I think the original issues raised have been addressed, so I'll close this issue. However, please do let us know of any other unexpected behavior.
Hi guys. I do confirm dual_moving_average.py works now, thanks. Concerning the others examples, I still get the same errors for those 3: dual_ema_talib.py -> ImportError: No module named talib (might have miss something in talib installation) pairtrade.py-> ValueError: You must define a handle_data function. olmar.py-> AttributeError: 'TradingAlgorithm' object has no attribute 'symbol'
talib is an optional dependency, so it's expected that that example will fail if talib is not installed. The other two examples should always work afaik. @StewartDouglas can you check and see if those are broken for you?
ACK, looking into this.
@fraka6 I can run both pairtrade.py and olmar.py directly from the command line as follows:
PYTHONPATH=. python zipline/examples/pairtrade.py
PYTHONPATH=. python zipline/examples/olmar.py
Can you confirm whether these work for you?
The reason that pairtrade.py is not working for you is that it cannot be run using scripts/run_algo.py. I'm not sure why olmar.py is failing for you, but I'm investigating.
olmar.py works for me when I run the following:
PYTHONPATH=. python scripts/run_algo.py -f zipline/examples/olmar.py --start 2004-1-1 --end 2008-1-1 --symbols 'AMD,CERN,COST,DELL,GPS,INTC,MMM'
@fraka6 If you could let us know whether this succeeds for you, or show us a stack trace if it fails, then it would be much appreciated.
hi @StewartDouglas. Its still not good. If I set the pythonpath to zipline, it crash before (ImportError: No module named _assets -> see bellow). It seems to be related to same issue reported here: https://groups.google.com/forum/#!topic/zipline/B_cKY4HrC2Q I tried it with python anaconda, python2.7, pip install & manual git pull (latest version & pip uninstall).
Here are my notes:
which python
/home/fpieraut/anaconda/bin/python
echo $PYTHONPATH /home/fpieraut/heroku/datascience/pytrade/zipline
python scripts/run_algo.py -f zipline/examples/olmar.py --start 2004-1-1 --end 2008-1-1 --symbols 'AMD,CERN,COST,DELL,GPS,INTC,MMM'
Traceback (most recent call last):
File "scripts/run_algo.py", line 20, in
Hi @fraka6, sorry to hear it's still giving you trouble. Can you try running the following in your zipline repo (to compile the Cython files to C) and trying again:
python setup.py build_ext --inplace
Interesting. It is working, I had to install contextlib2 and bottleneck to make the example working fully. thanks. Any idea why I have to do this (python setup.py ...)? Francis