def make_pipeline(): # Screen out penny stocks and low liquidity securities. dollar_volume = AverageDollarVolume(window_length=20) is_liquid = dollar_volume.rank(ascending=False) < 1000 # Create the mask that we will use for our percentile methods. base_universe = (is_liquid) # Filter down to stocks in the top/bottom 10% by sentiment rank factor = WeightedSentimentByVolatility() longs = factor.percentile_between(90, 100, mask=base_universe) shorts = factor.percentile_between(0, 10, mask=base_universe) # Add Accern to the Pipeline pipe_columns = { 'longs':longs, 'shorts':shorts } # Set our pipeline screens pipe_screen = (longs | shorts) & (factor != 0) # Create our pipeline pipe = Pipeline(columns = pipe_columns, screen = pipe_screen) return pipe
def initialize(context): # Create pipeline pipe = Pipeline() pipe = attach_pipeline(pipe, name='factors') pipe.add(PsychSignal(), "psychsignal_sentiment") #Screen out penny stocks and low liquidity securities dollar_volume = AverageDollarVolume(window_length=20) # Only look at top 1000 most liquid securities liquidity_rank = dollar_volume.rank(ascending=False) < 200 pipe.set_screen((dollar_volume > 10**7) & (liquidity_rank)) # Set our shorts and longs and define our benchmark context.spy = sid(8554) context.shorts = None context.longs = None schedule_function(rebalance, date_rules.every_day()) schedule_function(cancel_open_orders, date_rules.every_day(), time_rules.market_close()) set_commission(commission.PerShare(cost=0, min_trade_cost=0)) # no cost to trading set_slippage(slippage.FixedSlippage(spread=0))
def make_pipeline(): # Screen out penny stocks and low liquidity securities. dollar_volume = AverageDollarVolume(window_length=20) is_liquid = dollar_volume.rank(ascending=False) < 1000 # Add pipeline factors impact = alphaone_free.impact_score.latest sentiment = alphaone_free.article_sentiment.latest return Pipeline(columns={ 'impact': impact, 'sentiment': sentiment, }, screen=is_liquid)