Notebook
In [5]:
import numpy as np

from quantopian.pipeline import Pipeline
from quantopian.pipeline import CustomFactor
from quantopian.pipeline.filters import QTradableStocksUS
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.research import run_pipeline

period_start = '2019-05-31'
period_end = '2019-05-31'

class Vol_z_score(CustomFactor):  
    inputs = [USEquityPricing.volume]  
    window_length = 21
    def compute(self, today, assets, out, volume):
        latest  = volume[0, :]
        mean    = np.nanmean(volume, axis=0)
        std     = np.nanstd(volume, axis=0)
        z_score = (latest - mean)/std  
        out[:]  = z_score
            
universe = QTradableStocksUS()

zs = Vol_z_score(mask=universe)

universe = universe & zs.notnull()

pipe = Pipeline(  
    columns={  
        'z-score': zs,
    },  
    screen=universe,  
)

data_output = run_pipeline(pipe, period_start, period_end)  
print(data_output.head())

Pipeline Execution Time: 0.17 Seconds
                                              z-score
2019-05-31 00:00:00+00:00 Equity(2 [ARNC])   3.474207
                          Equity(24 [AAPL])  3.081325
                          Equity(41 [ARCB]) -0.930386
                          Equity(52 [ABM])   3.369718
                          Equity(53 [ABMD])  0.237593
In [ ]: