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.head()
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
result = run_pipeline(make_pipeline(), start_date = '2015-05-05', end_date='2015-05-05')
type(result)
result.head()
len(result)
from quantopian.pipeline.data.sentdex import sentiment
def make_pipeline():
sentiment_factor = sentiment.sentiment_signal.latest
universe = (Q1500US() & sentiment_factor.notnull())
pipe = Pipeline(columns={'sentiment': sentiment_factor,
'longs': (sentiment_factor>=4),
'shorts': (sentiment_factor<=-2)},
screen=universe)
return pipe
result = run_pipeline(make_pipeline(),start_date='2015-01-01', end_date='2016-01-01')
result.head()
assets = result.index.get_level_values(level=1).unique()
len(assets)
price = get_pricing(assets, start_date='2016-03-01', end_date='2016-06-01', fields = 'open_price')
import alphalens
factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factor = result['sentiment'],
prices = price,
quantiles = 2,
periods = (1,5,10))
alphalens.tears.create_full_tear_sheet(factor_data)