Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Designing a multi-strategy portfolio in Zipline for Quantopian

Dear all,

Attached is an example for combining multiple strategies, designed in Zipline, in a single quantopian script, using my zipeline2quantopian script. It contains simple portfolio cash allocation for each strategy, and a dictionary aggregation mechanism to eventually synchronize positions in similar instruments but triggered by different strategies.

I have chosen very simple strategies (should I even call that a strategy?), BUT I've applied them to no-split (or few), no-dividend instruments so that the comparison with quantopian split-adjusted only price should correlate well with that of Yahoo in Zipline.

The strategy and results are in a github repo here: https://github.com/florentchandelier/zipline2quantopian/tree/master/example/multi-strat_multi-instru

HTH.

Updated on Post April 12th .... new ATS architecture.

4 responses

Thanks a lot for posting this. I was considering making a system like this myself since I like to work in PyCharm. I forked your repo, but I seem to be running into a problem with my system not being able to import get_environment from zipline.api

This looks good (I think):

In [26]: print zipline.__version__  
0.7.0  

... but tab complete in iPython looks like this for zipline.api:

In [25]: from zipline.api import  
FixedSlippage          get_datetime           order_percent          set_commission         slippage  
VolumeShareSlippage    get_open_orders        order_target           set_long_only          symbol  
add_history            get_order              order_target_percent   set_max_order_count    zipline  
batch_transform        history                order_target_value     set_max_order_size  
cancel_order           math_utils             order_value            set_max_position_size  
commission             order                  record                 set_slippage

I tried importing zipline first, and also importing zipline.api first, due to a bug I saw mentioned in a forum, but to no avail.

pip install zipline --upgrade says I'm up to date. I'd rather not use conda since it messes with my virtualenvs.

Any ideas? And thanks again.

In [25]: from zipline.api import get_environment  
---------------------------------------------------------------------------  
ImportError                               Traceback (most recent call last)  
<ipython-input-25-97e3a2e38b58> in <module>()  
----> 1 from zipline.api import get_environment

ImportError: cannot import name get_environment  

I've just got this set up after several hours of head scratching. The version installed via pip install is an older version. I ended up downloading the package from GitHub and installing manually. Apparently the last pip version update didn't take.

Hi, thanks for your reply. Yep, I also scratched my head until I came to the same conclusion. I've never come across a version compatibility issue due to pip being out of date before, at least that I knew at the time. I'll be on the lookout for it in the future now though.

Thanks again to Florent for sharing this package too.

Updated architecture: PortfolioManager, OrderManager and StrategyDesign & StrategyPortfolio
The objective was to track instruments' positions per strategies, even though the strategy are using percent_orders()
The Quantopian file is still automatically generated from multiple zipline files, through an automated script.
Refer to https://github.com/florentchandelier/zipline2quantopian