Back to Community
Example Markowitz Portfolio notebook uses old zipline API

The final code cell in the example notebook starts with the following code

import zipline  
from zipline.api import (add_history,  

from zipline import TradingAlgorithm  

which appears to be using an old version of zipline. Running the code produces the following error:

ImportError                               Traceback (most recent call last)  
<ipython-input-18-b571c36c1a72> in <module>()  
      1 import zipline  
----> 2 from zipline.api import (add_history,  
      3                          history,  
      4                          set_slippage,  
      5                          slippage,

ImportError: cannot import name add_history  
8 responses

add_history is part of the old API, and it's no longer necessary. So if you remove all instances of it, including from the import statement, the code should work fine.

May I ask where you got the example notebook from so that we can correct it?


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.

Oh, I just opened up the Notebooks section and there's a folder called "Tutorials and Documentation" which contains a number of example notebooks. I've attached the notebook itself or reference.

Loading notebook preview...

Thanks for the info, Sam. I've made an internal ticket for the notebook so it can be fixed.

The notebook still has the same issue. Has anyone been able to find a workaround?


The Markowitz Portfolio notebook is still using the old zipline API (add_history) and still has the same issue. Has anyone been able to find a workaround?

The notebook is still the older one, no changes.

Could anyone help with it?


The notebook still has the error.

Please help


Remove add_history in the import and comment "add_history(100, '1d', 'price')" in initialize function.
However, you might get the following error
RemoteDataError: Unable to read URL:
ie, rejected by google for unusual access "... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now."