Research & backtesting in the Notebook environment

To run your research environment you first need to make sure jupyter is installed.
Follow the instructions in Jupyter.org
e.g. pip install notebook
Start your Jupyter server
jupyter notebook
You might need to add the jupyter kernel to be able to work with your virtual environment.
This should get it working, and search online if you face issue:
pip install ipykernel
python -m ipykernel install --user --name zipline-trader

Working With The Research Environment

This was one of Quantopian’s strengths and now you could run it locally too.
In the next few examples we will see how to:
  • Load your Alpaca (or any other) data bundle

  • How to get pricing data from the bundle

  • How to create and run a pipeline

  • How tu run a backtest INSIDE the notebook (using python files will follow)

  • How to analyze your results with pyfolio (for that you will need to install pyfolio)

Loading Your Data Bundle

Now that you have a jupyter notebook running you could load your previously ingested data bundle.
Follow this notebook for a usage example: Load Data Bundle.

Simple Pipeline

You can work with pipeline just as it was on Quantopian, and in the following example you could see hwo to create a simple pipeline and get the data: Simple Pipeline.

Factors and Alphalens

Factors could be used to filter and/or rank your pipeline output and help you choose the better
stocks to trade for your scenario. Quantopian created Alphalens to help you analyze the quality
of your factors.
This package is not maintained by quantopian anymore, so I recommend installing from my fork (I had to fix some stuff to make it work properly). Do this:
pip install git+https://github.com/shlomikushchi/alphalens#egg=alphalens

Sector Classifier

I added a builtin Sector classifier called ZiplineTraderSector. It is based on the work in https://github.com/pbharrin/alpha-compiler.
It allows you to work in specific sectors inside your universe. e.g: analyze how tech stocks respond to a certain factor.
In the following example we can see how to use it on some factors we create. Alphalens Example.

Run and analyze a backtest

Running a backtest is the way to test your ideas. You could do it inside a notebook or in your python IDE (your choice).
The advantage of using the notebook is the ability to use Pyfolio to analyze the results in a simple manner as could be seen here: Bactesting.