Notebook
In [7]:
from quantopian.pipeline.factors import AverageDollarVolume, RSI, SimpleMovingAverage, CustomFactor, BollingerBands
from quantopian.pipeline.filters import Q500US, QTradableStocksUS, Q1500US
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.research import run_pipeline
import talib
import numpy as np
from quantopian.pipeline import Pipeline
In [8]:
class OHLC4(CustomFactor):  
    inputs = [USEquityPricing.high, USEquityPricing.low, USEquityPricing.close, USEquityPricing.open]  
    window_length = 2  
    window_safe=True  
    def compute(self, today, assets, out, high, low, close, open):  
        out[:] = (open[-1] + high[-1] + low[-1] + close[-1]) / 4.0
In [11]:
def make_pipeline():

    m = QTradableStocksUS()

    bband = BollingerBands(inputs=[OHLC4(mask=m)], window_length=20, k=2)  
    low_bb = bband.lower  
    high_bb = bband.upper  
    alpha = low_bb / high_bb  

    pipe = Pipeline(
        columns={
            'bb_upper' : high_bb,  
            'alpha' : alpha,  
            'bb_lower' : low_bb
        },
        screen = Q500US()
    )
    
    return pipe

#Run the pipeline to view output securities:
run_pipeline(make_pipeline(), '2019-05-24', '2019-05-24')
Out[11]:
alpha bb_lower bb_upper
2019-05-24 00:00:00+00:00 Equity(2 [ARNC]) 0.915473 20.917952 22.849331
Equity(24 [AAPL]) 0.812702 176.002686 216.564742
Equity(53 [ABMD]) 0.890210 247.504154 278.029021
Equity(62 [ABT]) 0.938845 74.586337 79.444788
Equity(67 [ADSK]) 0.935544 167.205012 178.724988
Equity(76 [TAP]) 0.880540 56.004350 63.602275
Equity(114 [ADBE]) 0.930907 268.928275 288.888325
Equity(122 [ADI]) 0.796891 96.437009 121.016616
Equity(128 [ADM]) 0.870708 38.935288 44.716817
Equity(161 [AEP]) 0.947925 82.948185 87.505053
Equity(166 [AES]) 0.900273 15.705322 17.445060
Equity(185 [AFL]) 0.939378 49.195405 52.370210
Equity(216 [HES]) 0.912213 60.747227 66.593248
Equity(239 [AIG]) 0.825491 45.078861 54.608539
Equity(300 [ALK]) 0.946058 59.591649 62.989417
Equity(337 [AMAT]) 0.855972 38.688423 45.198238
Equity(351 [AMD]) 0.936122 26.395960 28.197140
Equity(368 [AMGN]) 0.905611 164.518494 181.665757
Equity(438 [AON]) 0.969952 175.669723 181.111782
Equity(448 [APA]) 0.854486 28.509904 33.364971
Equity(455 [APC]) NaN NaN NaN
Equity(460 [APD]) 0.960627 201.141502 209.385648
Equity(465 [APH]) 0.857302 87.714342 102.314408
Equity(630 [ADP]) 0.952256 156.415999 164.258276
Equity(679 [AXP]) 0.960965 115.593150 120.288600
Equity(693 [AZO]) 0.921169 969.748507 1052.737018
Equity(698 [BA]) 0.861905 333.635331 387.090422
Equity(700 [BAC]) 0.877874 27.484844 31.308431
Equity(734 [BAX]) 0.972894 74.905169 76.992131
Equity(739 [BBBY]) 0.807854 13.980517 17.305758
... ... ... ...
Equity(49222 [TDOC]) 0.895399 56.530710 63.134665
Equity(49229 [KHC]) 0.947858 31.558546 33.294604
Equity(49242 [PYPL]) 0.942475 107.393672 113.948553
Equity(49288 [LITE]) 0.630282 43.331809 68.749916
Equity(49496 [FDC]) NaN NaN NaN
Equity(49506 [HPE]) 0.856452 13.949881 16.287994
Equity(49608 [MTCH]) 0.755561 57.036032 75.488293
Equity(49610 [SQ]) 0.827869 61.004352 73.688448
Equity(49655 [TEAM]) 0.760911 102.218085 134.336365
Equity(50049 [FTV]) 0.888955 77.660223 87.361227
Equity(50077 [TWLO]) 0.890342 125.871998 141.374852
Equity(50288 [TTD]) 0.743107 176.079398 236.950202
Equity(50338 [NTNX]) 0.773756 33.995996 43.936329
Equity(50392 [YUMC]) 0.804761 39.212850 48.726086
Equity(50428 [AA]) 0.857434 23.322498 27.200327
Equity(50683 [SNAP]) 0.872116 10.310200 11.822050
Equity(50716 [DXC]) 0.758000 51.542555 67.998070
Equity(50758 [OKTA]) 0.902055 100.104190 110.973435
Equity(50860 [VST]) 0.847806 23.600316 27.836934
Equity(50970 [ATUS]) 0.922942 23.041308 24.965067
Equity(51012 [BHGE]) 0.839864 21.327740 25.394280
Equity(51157 [DWDP]) 0.709869 27.448310 38.666737
Equity(51231 [ROKU]) 0.578909 54.759350 94.590625
Equity(51314 [MDB]) 0.869856 127.703455 146.809845
Equity(51854 [DBX]) 0.885936 22.022071 24.857404
Equity(51895 [SPOT]) 0.902550 127.392140 141.146860
Equity(51937 [DOCU]) 0.878999 50.833874 57.831576
Equity(52211 [TLRY]) 0.807600 43.211461 53.506039
Equity(52424 [ELAN]) NaN NaN NaN
Equity(52592 [LIN]) NaN NaN NaN

499 rows × 3 columns