Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Iterating Through Stocks In Pipeline
def pipeline(context):  
       returns = abs(Returns(window = 2))  
       stocks_to_iterate_through = returns.top(10)  
       Stock_List = {}  
       #Bit iffy on how to do this vv  
       for stock in stocks_to_iterate_through:  
              simple_beta = SimpleBeta(stock, regression_length=120)  
              mask = (simple_beta < 1.1) & (simple_beta > 0.9) & returns < 1.01  
              mcap = Fundamentals.market_cap.latest  
              Stock_List[Stock] = mcap.top(100, mask = mask)  
       #Bit iffy on how to do this ^^

       pipe = Pipeline(  
              Stock_List,  
              screen=QTradableStocksUS()  
       )  
       return pipe  

Does anyone know how to do this in pipeline? The code doesn't work, the basic problem is that mask is not iterable. I would like to find the top 10 stocks which have moved the most over the last time period, find the stocks which are correlated with them, but have not moved and return a stock specific list of those stocks.

I've checked, apparently you can do Stock_List['whatever you want in here'] = mcap.top(100, mask = mask) in pipeline and return Stock_List, however I can't work out how to iterate through a list of stocks which meet the basic criteria in pipeline.