Zipline command in IPython

147 views
Skip to first unread message

ka sin lai

unread,
Mar 4, 2017, 4:01:06 AM3/4/17
to Zipline Python Opensource Backtester
I have just tried to use simple command in IPython console (e.g. zipline bundles), but it shows error as below:


zipline bundles

Traceback (most recent call last):

  File "<ipython-input-2-4ade2f62695d>", line 1, in <module>
    get_ipython().magic('zipline bundles')

  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2158, in magic
    return self.run_line_magic(magic_name, magic_arg_s)

  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2079, in run_line_magic
    result = fn(*args,**kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\zipline\__main__.py", line 269, in zipline_magic
    standalone_mode=False,

  File "C:\ProgramData\Anaconda3\lib\site-packages\click\core.py", line 696, in main
    with self.make_context(prog_name, args, **extra) as ctx:

  File "C:\ProgramData\Anaconda3\lib\site-packages\click\core.py", line 621, in make_context
    self.parse_args(ctx, args)

  File "C:\ProgramData\Anaconda3\lib\site-packages\click\core.py", line 885, in parse_args
    ' '.join(map(make_str, args))))

  File "C:\ProgramData\Anaconda3\lib\site-packages\click\core.py", line 476, in fail
    raise UsageError(message, self)

UsageError: Got unexpected extra argument (bundles)



Anyone has ideas of the error?? I have already run "%load_ext zipline"....

Thanks,
Jason

Peter Harrington

unread,
Mar 4, 2017, 9:35:37 AM3/4/17
to Zipline Python Opensource Backtester
"zipline bundles" is a command that should be run in your terminal.  It is not Python code. 
When you install Zipline it creates a stand alone program called zipline that you can use to run your algos manage bundles, etc.  
There are multiple ways to use the zipline code, one is through this program, one is through a Python interpreter (like IPython) and there may be a third way that I never use.  

Pritesh Patel

unread,
Mar 5, 2017, 10:28:12 AM3/5/17
to Zipline Python Opensource Backtester
I just started using zipline with ipython. 
As you mentioned you have already load ext zipline, just make sure as separate from your algo and top of the algorighthm write down..

%%zipline -s 2012-01-01 -e 2014-01-01 -b [your bundle]

In case of 2012-1-1 it was giving me error but work with leading zero so wondering same issue with you as well.

Thanks,
Pritesh

fva...@quantopian.com

unread,
Mar 8, 2017, 1:20:24 PM3/8/17
to Zipline Python Opensource Backtester
Hi there, thanks for posting about this.

The command zipline bundles should be run in your command prompt/terminal. If you would like to run in IPython, you can run it with an exclamation point in front of it: ! zipline bundles, although I don't recommend this.

If you're trying to use a bundle to run some algo code in IPython, then running %load_ext zipline in a separate cell (above your algo code cell), and then %%zipline --start <start_date> --end <end_date> -b <bundle_name> in the same cell as your algo code, would be the way to go about doing that.

You can find more information on the command line interface here :)

Thanks,
Freddie

Davis Owen

unread,
Mar 9, 2017, 8:02:29 PM3/9/17
to Zipline Python Opensource Backtester
You could also try

from zipline.data.bundles import bundles
for i,j in bundles.iteritems():
    print(i)

but this is not nearly as good or convenient as just running from cmdline as others have said. 

Also there are multiple ways to run zipline code in IPython. It is worth noting you can create a TradingAlgorithm() object with certain parameters, and run it using class method .run() with custom data input. This one is a little harder to get working I believe because I had some trouble with using bundle data.

You can also use

from zipline import run_algorithm

and use results= run_algorithm(args) to get results, then analyze using pyfolio to create a nice tear sheet
Reply all
Reply to author
Forward
0 new messages