cannot run pairtrade example, Error_MSG: "You must define a handle_data function" zipline_ver:0.9.0

39 views
Skip to first unread message

Ronald Sutedja

unread,
Jul 18, 2015, 11:13:13 AM7/18/15
to zip...@googlegroups.com
Hello, trying to run pair_trade example:

python run_algo.py -f pairtrade.py -o output.pickle

and got the following output: 

Traceback (most recent call last):
  File "run_algo.py", line 23, in <module>
    run_pipeline(print_algo=True, **parsed)
  File "C:\Users\Ronald Sutedja\Anaconda\lib\site-packages\zipline\utils\cli.py", line 244, in run_pipeline
    end=end)
  File "C:\Users\Ronald Sutedja\Anaconda\lib\site-packages\zipline\algorithm.py", line 243, in __init__
    raise ValueError('You must define a handle_data function.')
ValueError: You must define a handle_data function.


Scott Sanderson

unread,
Jul 21, 2015, 11:39:39 AM7/21/15
to zip...@googlegroups.com
Hi Ronald,

Sorry for the long delay in replying.

The pairtrade algo in the examples directory is currently using an older API that required subclassing TradingAlgorithm and implementing `initialize` and `handle_data` as methods rather than top-level functions.  The run_algo entrypoint, by contrast, expects a script with initialize and handle_data as top-level functions, so it doesn't understand algos written in the older style, which is why you get the error message about not finding handle_data.  We eventually plan to deprecate the old subclass-based API entirely, at which point we'll go through and port the examples to the new style.

In the meantime, you can run the pairtrade example as a standalone script by invoking it directly with python, e.g. "python zipline/examples/pairtrade.py".

-Scott

Ronald Sutedja

unread,
Jul 21, 2015, 12:22:28 PM7/21/15
to Scott Sanderson, zip...@googlegroups.com
Thanks, 

I traced through the code apparently instead of doing data[self.PEP], it should be replaced with data[self.PEP.sid]. This make it work. I'm planning to fork it from github and make a unit test out of it. Looks like a typo there. Thanks for replying. 

--
You received this message because you are subscribed to a topic in the Google Groups "Zipline Python Opensource Backtester" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zipline/-jCn3MhX1d4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zipline+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Ronald Sutedja
Reply all
Reply to author
Forward
0 new messages