Notebook
In [9]:
from quantopian.pipeline import Pipeline
from quantopian.pipeline import CustomFactor
from quantopian.research import run_pipeline
from quantopian.pipeline.data import morningstar
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import Latest, AverageDollarVolume
from quantopian.pipeline.classifiers.morningstar import Sector
from quantopian.pipeline.filters.morningstar import IsPrimaryShare

from quantopian.pipeline.data.psychsignal import stocktwits_free as stocktwits
from quantopian.pipeline.data.sentdex import sentiment_free as sentdex
from quantopian.pipeline.data.accern import alphaone_free as accern
In [10]:
pipe = Pipeline()
    
sentiment = sentdex.sentiment_signal.latest

dollar_volume = AverageDollarVolume(window_length=20)
is_liquid = dollar_volume.top(500)

sector = morningstar.asset_classification.morningstar_sector_code.latest

initial_screen = (is_liquid & sector.eq(101) & IsPrimaryShare())

combined_rank = sentiment.rank(mask=initial_screen)
pipe.add(combined_rank, 'combined_rank')

shorts = combined_rank.percentile_between(0, 20)
longs = combined_rank.percentile_between(80, 100)

pipe.set_screen(longs | shorts)

pipe.add(longs, 'longs')
pipe.add(shorts, 'shorts')
In [13]:
pipe.show_graph(format='png')
Out[13]:
In [ ]: