Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to make a filter given a list of stocks

Newbie Question :)

Now I have a list of stocks. How can I make a filter to judge whether a specific stock is in this list or not?
For now I can only make a function but not a FILTER.
I really need a filter for pipeline screens.

Thanks!

3 responses

You can make a CustomFilter similar to the way one makes a CustomFactor. Just return a True or False value.

There are a couple of approaches to filtering a list of securities when using a pipeline. Maybe search the forums for "symbols" or "list". Here is one such post which I attached code for doing (I believe) just what you wanted. https://www.quantopian.com/posts/using-a-specific-list-of-securities-in-pipeline#57964b09938eade52300015b

Good luck,

Dan

Thanks so much Dan! You are awesome!

Just noticed a built in filter that filters to a list of equities. Can be used for a single equity or a list of equities.

from quantopian.pipeline.filters import  StaticAssets

aapl = StaticAssets(symbols(['AAPL']))  
aapl_ibm = StaticAssets(symbols(['AAPL', 'IBM']))