Notebook
In [1]:
from quantopian.pipeline.factors import AverageDollarVolume, RSI, SimpleMovingAverage
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.research import run_pipeline
import talib
from quantopian.pipeline import Pipeline
In [2]:
def make_pipeline():

    #Factors and corresponding filters for RSI of over 50 and 7 day fast moving average > 30 day slow moving average:

    #RSI:
    rsi = RSI()
    #Moving average for last 7 days:
    sma_7 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=7)
    #Moving average for last 30 days:
    sma_30 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=30)

    #Construct a screen that uses the factors above:
    rsi_filter = rsi > 50
    sma_filter = sma_7 > sma_30
    tradeable_assets = rsi_filter & sma_filter

    #Construct the pipeline that incorporates factors and filters from above:
    pipe = Pipeline(
        columns={
            'RSI': rsi,
            'sma_7': sma_7,
            'sma_30': sma_30,
        },
        screen = tradeable_assets
    )
    
    return pipe
In [3]:
#Run the pipeline to view output securities:
result = run_pipeline(make_pipeline(), '2017-01-01', '2017-08-02', chunksize=252)
In [4]:
result
Out[4]:
RSI sma_30 sma_7
2017-01-03 00:00:00+00:00 Equity(24 [AAPL]) 62.433862 113.368433 116.632857
Equity(66 [AB]) 53.571429 23.119167 23.500000
Equity(70 [VBF]) 60.901864 18.208480 18.411429
Equity(84 [ACET]) 57.364341 20.722753 21.695714
Equity(106 [ACU]) 79.449541 22.628433 24.117143
Equity(112 [ACY]) 86.231884 9.201423 9.389286
Equity(149 [ADX]) 52.259036 12.629808 12.816429
Equity(161 [AEP]) 63.765910 61.030533 63.001571
Equity(266 [AJG]) 65.024631 50.972391 51.874286
Equity(270 [AKRX]) 79.524680 20.876667 21.376429
Equity(312 [ALOT]) 61.201044 13.651491 14.074167
Equity(351 [AMD]) 64.977645 10.044167 11.601429
Equity(357 [TWX]) 64.926931 94.204182 96.450714
Equity(368 [AMGN]) 58.703939 145.917000 147.134286
Equity(371 [TVTY]) 52.752294 22.923333 23.003571
Equity(450 [CLFD]) 55.769231 20.140833 21.121429
Equity(474 [APOG]) 63.047619 49.776000 53.611429
Equity(535 [ARTW]) 58.823529 3.097778 3.121429
Equity(610 [ATNI]) 56.380866 76.262833 80.717031
Equity(612 [ATO]) 56.117021 72.934282 74.400000
Equity(630 [ADP]) 77.968176 98.379357 102.944286
Equity(659 [AMAG]) 54.210526 33.971667 35.042857
Equity(677 [AXAS]) 72.222222 2.265333 2.618571
Equity(680 [AXR]) 50.526778 7.319828 7.494286
Equity(779 [BCR]) 72.308546 216.389333 222.602857
Equity(785 [INSI]) 74.111615 18.652751 18.905857
Equity(790 [BDL]) 69.659443 23.733154 24.306000
Equity(799 [BEAV]) 51.123596 59.664167 60.075000
Equity(845 [BGG]) 51.715773 21.699746 22.712857
Equity(856 [BHE]) 64.705882 29.355000 30.764286
... ... ... ... ...
2017-08-02 00:00:00+00:00 Equity(50987 [OCIO]) 73.529412 25.171950 25.420000
Equity(50988 [CBH]) 51.250000 10.139636 10.157143
Equity(50995 [USMF]) 63.919129 25.119409 25.359857
Equity(50996 [TTAI]) 66.145833 25.432087 25.775429
Equity(50999 [GOAU]) 70.383693 11.862087 12.169714
Equity(51007 [SCE_PRL]) 73.737374 25.291429 25.561429
Equity(51008 [CISN]) 64.885496 10.825714 10.867143
Equity(51011 [CODI_PRA]) 54.320988 24.934368 24.962571
Equity(51015 [PMT_PRB]) 53.061224 25.041833 25.081286
Equity(51021 [FANZ]) 72.972973 20.351667 20.435571
Equity(51022 [IBD]) 79.279279 25.235714 25.295000
Equity(51024 [IGEB]) 100.000000 50.426000 50.570000
Equity(51025 [SUSB]) 100.000000 25.145000 25.180000
Equity(51026 [USEQ]) 60.326087 25.356071 25.386143
Equity(51027 [HYDB]) 100.000000 50.740000 50.895000
Equity(51028 [SPMV]) 65.104167 25.349333 25.515000
Equity(51032 [REEM]) 100.000000 26.283750 26.445000
Equity(51035 [FNG]) 58.099945 20.861571 20.919286
Equity(51036 [EUXL]) 62.430323 26.297462 26.632833
Equity(51037 [AKCA]) 73.754691 12.912077 14.388143
Equity(51038 [MYND_W]) 66.225166 0.848800 0.871200
Equity(51042 [AUG]) 75.198728 2.710636 2.782500
Equity(51043 [BCAC_W]) 100.000000 0.410000 0.421000
Equity(51045 [BCAC]) 72.727273 9.805714 9.806667
Equity(51051 [KALA]) 70.192308 19.556111 19.752143
Equity(51054 [TRTX]) 74.647887 19.746667 19.785714
Equity(51058 [AMH_PRG]) 63.349515 25.137778 25.145429
Equity(51064 [PETQ]) 57.692308 22.944375 22.957857
Equity(51066 [OSPR_U]) 75.000000 10.023125 10.023571
Equity(51067 [EFBI]) 65.000000 15.199125 15.239000

587982 rows × 3 columns