Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline filter to a single stock

Hello,

Before I start I know pipeline is used to create dynamic stock selection but I want to use it in a notebook where you can apply factors to the pipeline but filter it to just one stock at the end. (Ideally the SPY500).

Is it possible to, for example, create a pipeline that gets the RSI for the past week and then filters the pipeline data so that it only shows for the SPY500 in a notebook?

Something along the lines of...

def make_pipeline():  
    rsi = RSI(inputs=[USEquityPricing.close], window_length=5)  
    return Pipeline(  
        columns={  
            'RSI': rsi,  
       },  
       screen=sid == 8554 or symbol == 'SPY',  
    )

Thanks, Haydn

5 responses

Found this code from a user called Matt

class SidInList(CustomFilter):  
    """  
    Filter returns True for any SID included in parameter tuple passed at creation.  
    Usage: my_filter = SidInList(sid_list=(23911, 46631))  
    """  
    inputs = []  
    window_length = 1  
    params = ('sid_list',)

    def compute(self, today, assets, out, sid_list):  
        out[:] = np.in1d(assets, sid_list)  

and using it with pipeline like this...

def make_pipeline():  
    rsi = RSI(inputs=[USEquityPricing.close], window_length=10)  
    symbol = SidInList(sid_list=(8554))  
    return Pipeline(  
        columns={  
            'RSI': rsi,  
            'symbol': symbol,  
       },  
       screen=symbol,  
    )  

filters to just one stock!

Sorry for the naive question, I'm a newbie :) Could you please elaborate on this code? You're wanting to determine the RSI of SPY?

Thanks Haydn, this helped me out a lot - In case other noobs like myself come across this, CustomFilter isn't mentioned in the API help, reference with :

from quantopian.pipeline import Pipeline, CustomFactor, CustomFilter  

Is this really the only way to run pipelines in research, for a particular stock? It's not very obvious :-/

You may want to have a look at the help page on the StaticAssets filter:

from quantopian.pipeline.filters import StaticAssets

class StaticAssets(assets)

A Filter that computes True for a specific set of predetermined assets.

StaticAssets is mostly useful for debugging or for interactively computing pipeline terms for a fixed set of assets that are known ahead of time.  
Parameters: assets (iterable[Asset]) – An iterable of assets for which to filter.

See also:

https://www.quantopian.com/posts/search?q=StaticAssets

Much cleaner, thanks Grant!