Hello and welcome to my very first blog post. In this post I will cover how to install zipline locally using Python 3.5.4. Zipline is in my opinion the best finance backtesting strategy system for Python. While you can use Quantopian for basic strategy backtesting, for free, local zipline offers you a lot of more options. Zipline offers you a lot of different datasets, even your own for example if you need minute data, which is not provided by zipline, the most popular one is probably Quandl. If you ant to do live trading (and potentially lose money), then there’s an option for you called zipline-live. Also if your strategy requires heavy deep learning or you want to do high frequency trading you have to go with a local (or some individually hosted)environment.
So let’s get started with the installation. First installing zipline can be a absolute pain because it requires a lot of other packages and in case one is buggy the whole system could crash. LOL. First for this tutorial I am gonna be using Python 3.5 since it’s currently the most compatible version with all the other packages I use. I would also recommend you using Python 3.5 (as of this writing). Using Python 3.5 we can install the older pandas version, which is required by zipline. This version can’t be installed on Python 3.6. I have zipline installed on Windows and Ubuntu
I am personally using Zipline 1.3.0 on Python 3.5 on Windows at the moment.
Installation on Ubunntu 18.04:
Installation on Windows:
First on Windows it’s a bit hacky. At the time I am writing this Python 3.5 is the standart for Zipline 1.3.0. A key dependence of Zipline is pandas, here you need pandas 0.18.1 or 0.22.0, which is an older release. To install to Python 3.5, here’s the list of dependences, linking to the unofficial binaries page:
All of those can be downloaded from Unofficial Windows Binaries for Python site.
Now if that is all done, we can continue installing with pandas. As I mentioned already we need to use either pandas==0.18.1 or pandas==0.22.0. But first we need to do pip3 install zipline. This may probably fail. But then it downloads the other non C++ libs. Now if that is done let’s run pip3 install pandas=0.18.1 or replace 0.18.1 with 0.22.0 if you need it for any reason.
Finally get zipline. I downloaded it from here
The last and fianl step is to install zipline. We need to do pip3 install –no-deps zipline-1.3.0-cp35-cp35m-win_amd64.whl. And then we are done.
Test your installation:
Run python and do a import zipline
Now first for this you need a Quandl account to get all the financial data. It’s worth mentioning that you need to verify your email adress so that you can use your API key. You should then find your quandl api key under your account. For Windows Users run setx QUANDL_API_KEY “your_api_key”. Now ingest your data using the following command: zipline ingest -b quandl. If you have a good internet connection that shouldn’t take too long.
In this case we use the “buy_appl” “strategy”, so we order 10 shares every day.
save the file as apple_backtest.py and run it on the command line using
For more detail about running zipline in an IPython Notebook, checkout the Zipline Doc
**Thanks for reading and maybe we see each other on Twitter @nowsden or reach out to me via firstname.lastname@example.org **
Disclaimer: This is for educational and informational purpose only.