# Query historical pricing data for TDG tdg_close = prices(assets = asset, start = analysis_start,end = analysis_end,) # Compute 20 and 50 day moving averages on pricing data tdg_sma20 = tdg_close.rolling(20).mean() tdg_sma50 = tdg_close.rolling(50).mean() # Combine results into a pandas DataFrame and plot tdg_pricing_dataframe = pd.DataFrame({ stock_symbol: tdg_close, 'SMA20': tdg_sma20, 'SMA50': tdg_sma50}) # Query returns data for TDG tdg_returns = returns(assets = symbols(stock_symbol),start = analysis_start,end = analysis_end,) # Plot pricing data tdg_pricing_dataframe.plot(title='TDG Close Price / SMA Crossover'); # ## Define Auxillary Data # In this section, datasets representing human behavioral factors such as preference, sentiment, and communication will be defined so that they may be later correlated to the security's performance, and fundamental data in order to determine whether public opinion, or strong fundamentals is driving share pricing. # # Historical fundamental data is pulled from Zipline/Quantopian's API which leverages Morningstar data. # The technical data is pulled from the Zipline/Quantopian Research API. # # The techincal datasets are: # 1. Stocktwits Message Volume # 2. Stocktwits Sentiment # 3. Twitter Message Volume
######DATA EXPLORATION#################### # Research environment functions from quantopian.research import returns, symbols # Select a time range to inspect period_start = '2014-01-01' period_end = '2014-12-31' # Query returns data for AAPL # over the selected time range aapl_returns = returns( assets=symbols('AAPL'), start=period_start, end=period_end, ) # Display first 10 rows aapl_returns.head(10) # Pipeline imports from quantopian.research import run_pipeline from quantopian.pipeline import Pipeline from quantopian.pipeline.factors import Returns from quantopian.pipeline.data.psychsignal import stocktwits # Pipeline definition def make_pipeline():