Notebook

Filter Specific List of Securities Custom Factor

In [2]:
from quantopian.pipeline import Pipeline, CustomFilter
from quantopian.research import run_pipeline

import numpy as np
In [3]:
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)
   
In [4]:
include_filter = SidInList(sid_list = (24, 8554)) # SID for APPL and SPY

pipe = Pipeline()
pipe.set_screen(include_filter)

results = run_pipeline(pipe, '2016-07-01', '2016-07-01')
    
results
Out[4]:
2016-07-01 00:00:00+00:00 Equity(24 [AAPL])
Equity(8554 [SPY])
In [ ]: