Back to Community
Zipline error

Hi everyone!

I am new in this community and very happy so far what I am learning, my big issue is I am getting error with Zipline, I copied the algorithm "Instability of Parameter Estimates" but I am getting this error:

%matplotlib inline import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import math
import zipline

%%zipline --start 2000-1-1 --end 2014-1-1 -o perf_dma from zipline.api import order_target, record, symbol, history, add_history

def sharpeRatio(asset, riskfree):
return np.mean(asset-riskfree)/np.std(asset-riskfree)
start = '2012-01-01'
end = '2013-01-01'
treasury_ret = get_pricing('BIL', fields='price', start_date=start, end_date=end).pct_change()[1:]
pricing = get_pricing('AMZN', fields='price', start_date=start, end_date=end)
returns = pricing.pct_change()[1:] # Get the returns on the asset

ERROR:root:Cell magic %%zipline not found.

Has anyone run into the same problem?

Thanks,
Vincent.

3 responses

Hi Vincent,

If you're trying to do this in one of our Research notebooks, it won't work because Research doesn't support the Zipline cell magic. You can instead backtest in Research using the technique demonstrated in this example notebook.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

@Vincent Hansen , I get the same error. Did you ever resolve this. I'm trying to run Zipline in a notebook on my desktop (outside the Research environment). In theory, we are supposed to be able to do that, no? So I'd like an answer to this question:

How do I import the Zipline "Cell Magic" into a Jupyter notebook I'm running on my desktop?

Obviously, I have successfully installed Zipline on my computer.

O.k., I'm going to answer my own question. Steps to run --help are:

  • Run a cell with %load_ext zipline
  • Run the command in the notebook with a single percent sign instead of two: %zipline run --help

This worked for me. Apparently, when this tutorial notebook was created, the double %% cell magic worked, but now it doesn't. It would be interesting to know why. Changes within the Zipline code in more recent versions, perhaps?