from quantopian.interactive.data.sentdex import sentiment
from quantopian.pipeline.filters.morningstar import Q1500US
type(sentiment)
dir(sentiment)
BAC = symbols('BAC').sid
bac_sentiment = sentiment[ (sentiment.sid==BAC) ]
bac_sentiment.head()
bac_sentiment.peek()
import blaze
bac_sentiment = blaze.compute(bac_sentiment)
type(bac_sentiment)
bac_sentiment.set_index('asof_date', inplace=True)
bac_sentiment['sentiment_signal'].plot()
bac_sentiment = bac_sentiment[ (bac_sentiment.index > '2016-06-01') ]
bac_sentiment['sentiment_signal'].plot()
from quantopian.pipeline import Pipeline
def make_pipeline():
return Pipeline()
from quantopian.research import run_pipeline
my_pipe = make_pipeline()
result = run_pipeline(my_pipe, start_date='2015-05-05', end_date='2015-05-05')
result.head()
len(result)
def make_pipeline_2():
#Factor returns
sentiment_factor = sentiment.sentiment_signal.latest
# Our universe is made up of stocks that have a non-null sentiment signal that was updated in
# the last day, are not within 2 days of an earnings announcement, are not announced acquisition
# targets, and are in the Q1500US.
universe = (Q1500US()
& sentiment_factor.notnull())
# A classifier to separate the stocks into quantiles based on sentiment rank.
# Go short the stocks in the 0th quantile, and long the stocks in the 2nd quantile.
pipe = Pipeline(
columns={
'sentiment': sentiment_factor,
'longs': (sentiment_factor >=4),
'shorts': (sentiment_factor<=2),
},
screen=universe
)
return pipe
result = run_pipeline(make_pipeline_2(), start_date='2015-01-01', end_date='2016-01-01')
sentiment.peek()
sentiment.sentiment_signal.latest