Back to Community
How do I set_benchmark in zipline in a research notebook?

from zipline.api import set_benchmark

InputRejected                             Traceback (most recent call last)  
/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in transform_ast(self, node)
   2905         for transformer in self.ast_transformers:  
   2906             try:  
-> 2907                 node = transformer.visit(node)  
   2908             except InputRejected:  
   2909                 # User-supplied AST transformers can reject an input by raising

/home/qexec-restricted/.ipython/profile_quippy/ipython_kernel_config.py in wrapper(*args, **kwargs)
     61         def wrapper(*args, **kwargs):  
     62             try:  
---> 63                 return f(*args, **kwargs)  
     64             except InputRejected:  
     65                 raise

/home/qexec-restricted/.ipython/profile_quippy/ipython_kernel_config.py in visit(self, node)
    191                 if violation_warning_message is not None:  
    192                     violation_message += violation_warning_message  
--> 193                 raise InputRejected(violation_message)  
    194             finally:  
    195                 self.visitor.violations = []

InputRejected: Importing set_benchmark from zipline.api raised an 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.  

(N.B. I'm happy to talk to a human about why I'm trying to use your documented functions in your environment. /snark)

Without it I simply get a "set_benchmark" global name not found.

1 response

Hi K.C. - Unfortunately set_benchmark works in the Quantopian IDE, but isn't yet available in zipline, which is why you don't see it under zipline.api. It is being worked on, so you can watch the zipline github issue if you like, but in the meantime you can try Karen's workaround for Research, which is to get the results of an IDE backtest that set the benchmark (look for "Benchmarks" in her first shared notebook in that thread).

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.