Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Q500 Filter does not seem to work properly

Using the first tutorial ('Getting Started'), lesson 4 it is not quite clear to me how the Q500 filter works or whether it works at all. When I use the line:

asset_list = pipeline_output.index.levels[1].unique()
asset_list.shape

out:
(9137,)

So there are (9137,) unique tickers in my pipeline??? I have used 2 days in in Jan 2018 as a time period. How is it possiible that I have(9137,)assets when the filter is supposed to be Q500?

Curiously enough, the number of element in my pipeline is only 23:

pipeline_output.shape

(23, 1)

4 responses

In fact, it appears that the command:

pipeline_output.index.levels[1]

is identifying all sorts of tickers that are actually not in my pipeline at all.

I'm not exactly sure why Pandas does this, but oftentimes when slicing a dataframe it keeps pointers to the rest of the data. Maybe someone else can explain why. Nonetheless, the zipline platform is applying this mask/slicing the dataframe before it returns it to you as "pipeline_output".

To get what you're after, try: pipeline_output.index.get_level_values(1).unique()

@Kyle M is right. Use the get_level_values method rather than index. There are several recent posts on this. You may want to look at them for a little more detail
https://www.quantopian.com/posts/strange-issue-with-pipeline-screen-equals-universe-not-working
https://www.quantopian.com/posts/am-i-doing-something-wrong-pipeline-row-count-star-not-consistent-star

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.

Very interesting that so many people discovered this almost at the same time, thank you both for your quick help with this!!

It might make sense to change this in the tutorial, since a lot of folks might copy it from there and continue using it.