Environment
CentOS 7
Install Anaconda3
Download package from https://www.anaconda.com/download/
./Anaconda3-5.2.0-Linux-x86_64.sh
Install zipline
conda create -n env_zipline python=3.5
source activate env_zipline
(env_zipline) $ conda install -c Quantopian zipline
(env_zipline) $ source deactivate
Integrate with Jupyter notebook
conda env list
source activate env_zipline
(env_zipline) $:~user$ conda install ipykernel
Change jupyternotebook_config.py ( in /home/[user]/.jupyter/ )
c.NotebookApp.allow_root = True
c.NotebookApp.ip = '*'
#c.NotebookApp.certfile = u'/root/.jupyter/mycert.pem'
c.NotebookApp.port= 8098
c.NotebookApp.notebook_dir = "/home/[user]/ipython"
(env_zipline) $: python -m ipykernel install --user --name env_zipline --display-name "conda env_zipline"
Run Jupyter notebook
jupyter notebook
Copy the token in the log message
In web browser access: http://xxx.xxx.xxx.xxx:8098
Add your password after input the token you copied.
In the web UI menu 'New' to select 'conda env_zipline' to create a Python 3 IPython file
Download default data bundle
Register account in https://www.quandl.com/account/api if haven't, and get the API Key.
(env_zipline) $:QUANDL_API_KEY=[your_api_key] zipline ingest -b quand
Create IPython file
In the web UI menu 'New' to select 'conda env_zipline' to create a Python 3 IPython file
Add the following code as dual_moving_average IPython file:
%load_ext zipline
%%zipline --start 2016-1-1 --end 2018-1-1
from zipline.api import symbol, order, record
def initialize(context):
pass
def handle_data(context, data):
order(symbol('AAPL'), 10)
record(AAPL=data[symbol('AAPL')].price)
You can run the IPython file
You can also create the similar Python file , and execute it in command line.
zipline run -f dual_moving_average.py --start 2014-1-1 --end 2018-1-1 -o dma.pickle