Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How do I select only profitable stocks from Q1500?

Hi,

I attempted to write something like this but it fails with error

NotImplementedError: couldn't find matching opcode for 'and_bbi'

Any ideas how I can do it please?

def make_pipeline():  
    profitable = mstar.valuation_ratios.ev_to_ebitda > 0  
    pipe = Pipeline(screen=Q1500US() & profitable)  
    sectors = Sector()  
    pipe.add(sectors, 'sector')  
    return pipe  
5 responses

Hi Pravin, you might just need to change the line where you instantiate your pipeline to this:

pipe = Pipeline(screen=(Q1500US() & profitable)) (note the extra parentheses)

If this doesn't help, do you have a backtest or notebook that you could share?

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.

I also get an error for the code below:

NotImplementedError: couldn't find matching opcode for 'and_bbi'
There was a runtime error on line 40.

Line 40: output = pipeline_output('my_pipe')

def make_pipeline(context):  
    profitable = mstar.valuation_ratios.ev_to_ebitda > 0  
    market_cap = mstar.valuation.market_cap.latest  
    top_market_cap = market_cap.top(context.n_stocks, mask = (Q1500US() & profitable))  
    return Pipeline(screen = top_market_cap)  

Ah, sorry guys, the problem is that mstar.valuation_ratios.ev_to_ebitda is a BoundColumn. It should instead be mstar.valuation_ratios.ev_to_ebitda.latest:

profitable = mstar.valuation_ratios.ev_to_ebitda.latest > 0

Hi Jamie -

How would one know that a given fundamental data set is a BoundColumn (and what does that mean)? When I look at https://www.quantopian.com/help/fundamentals, there is no indication of which data require .latest. Is this documented somewhere?

Thanks,

Grant

Hi Grant,

Here's the documentation on BoundColumns: https://www.quantopian.com/help#zipline_pipeline_data_dataset_BoundColumn

Lesson 9 in the Pipeline Tutorial also discusses BoundColumns and Datasets. You will probably find this lesson helpful.

.latest is an attribute of a BoundColumn that returns a Factor/Filter/Classifier that outputs the most recent value of the underlying data column. I'd also recommend visiting Lesson 3 which discusses .latest.