Back to Community
Pipeline Filter doesn't work

Hi there, before I start I appreciate everyone who lends a hand. That being said, here is my problem. I am filtering a pipeline to give me stocks between 500 million and 2 billion market cap. However, the filter doesn't seem to work, as the output shows securities way over 2 billion.

Attached is my notebook and my code is below.
Here is my code:

from quantopian.pipeline import Pipeline  
from quantopian.research import run_pipeline  
from quantopian.pipeline.data import morningstar  
from quantopian.pipeline.data import Fundamentals  
million = 1000000000  
billion = 1000000000000

market_cap = morningstar.valuation.market_cap.latest  
low = market_cap > 500 * million  
high = market_cap < 2 * billion  
small_cap = low & high

pe = Fundamentals.forward_pe_ratio.latest  
my_pipe = Pipeline(  
    columns={  
        'market_cap': market_cap,  
        'fpe': pe,  
    },  
    screen= small_cap  
)

date = '8/31/2017'  
result = run_pipeline(my_pipe, date, date)  
result.head()  

Thank you for the help!

Loading notebook preview...
Notebook previews are currently unavailable.
4 responses

You have too many zeros...

million = 1000000000  
billion = 1000000000000

This should be...

million = 1000000  
billion = 1000000000

Thank you! It seemed too long so I tried it several times. I guess dumb me just made that same mistake 3 times...

I use the code in pycharm with zipline. The following line is not working. looks like there's no moringstar in the library at all. Please help
from quantopian.pipeline.data import morningstar (I use 'from zipline.pipeline.data import morningstar')

Yi, I suggest you open a new post rather than reply to an old one.

Also, you'll get more help if you share the notebook or algorithm that has the error.

That said, my first guess is that your problem is an older API.

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.