Back to Community
Can't import zipline.TradingAlgorithm() or zipline.run_algorithm() in Notebook

Hi, I'm trying to run a backtest in the research environment. I can't seem to import zipline.run_algorithm() or zipline.TradingAlgorithm(). I get the following error:

"Importing zipline.run_algorithm raised ImportError. No modules or attributes with a similar name were found. Last warning! One more import error and your account will be suspended for security reasons until a human can talk to you. "

Needless to say, I tried to import it in several ways, several times. :)

How do I solve this? And what function do I use to run a backtest? They have very similar inputs.

Thank you.

4 responses

Hi David, as of June 18, we removed the ability to import and use the zipline.TradingAlgorithm class in Research and in Backtesting. You can read the reasoning behind why it was removed in this forum thread. The feature was poorly supported, as it make running pipelines within algorithms difficult, and it required static data to be passed into the constructor.

Because of this we recommend you move your work from the research environment to the IDE.

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.

Understood. Is there a way to analyze a DataFrame that I output at the end of the backtest (via log.info) in the notebook? I haven't found anything. Having to run a huge backtest and dealing with the log limitations takes a lot of time, that's the only reason I was looking to do the backtest with the Notebook.

Until Q's new end_of_backtest() function :) with extra room available, there's this, however it is still subject to the logging limits.
https://www.quantopian.com/posts/generate-a-report-at-the-end-of-backtest

Yes, I've been using something similar to that, although I didn't know about get_environment('end').date(), that will be really useful. From what I've been able to test, the logging limits aren't that extreme (you can print about 22 dataframes that are 12x7 per day), but maybe I could print a few dataframes at 1/2/3/4/5 days before the backtest ends, since the results would be identical with big backtests. I don't know if the logging limits allow that, I'll have to see. Thank you.