# Grab all the closing prices for the tech stock list into one DataFrame stocks = ['AAPL','GOOG','MSFT','AMZN','GE'] closing_df = DataReader(stocks,'google',start,end)['Close'] closing_df_2 = DataReader(stocks,'google',start,end)['Close'] # change the timestamp to date closing_df["Date"] = closing_df.index.date closing_df.set_index("Date", drop=True, inplace=True) # Let's compare the closing prices(Close) of 4 tech stocks #fig1 = plot(closing_df.iplot(fill=True, asFigure=True, title="Daily Closing Price")) fig1 = plot(closing_df.iplot(fill=True,asFigure = True, subplots = True, title='Compare Closing Prices')) #plotly.offline.iplot(fig1, filename = 'compare-closing-prices') ### CORRELATION ANALYSIS ### # Correlation is a statistical measure to analyze of how stocks move in # relation to one another. # Correlation is represented by correlation coefficient - PEARSON COEFFICIENT r # ranging between -1 and +1 # When the prices of two stocks usually move in a similar direction, # the stocks are considered positively correlated. The amount of # correlation ranges from 0, which means no correlation, to 1, # which means perfect correlation. Perfect correlation means the # relationship that appears to exist between two stocks is positive 100% # of the time.
} fig = dict(data=data, layout=layout) #plotly.offline.plot(fig, filename='google-recession-candlestick') # Grab all the closing prices for the tech stock list into one DataFrame stocks = ['AAPL', 'GOOG', 'MSFT', 'AMZN'] closing_df = DataReader(stocks, 'yahoo', start, end)['Adj Close'] closing_df_2 = DataReader(stocks, 'yahoo', start, end)['Adj Close'] # change the timestamp to date closing_df["Date"] = closing_df.index.date closing_df.set_index("Date", drop=True, inplace=True) # Let's compare the closing prices(Adj Close) of 4 tech stocks fig1 = closing_df.iplot(asFigure=True, subplots=True, title='Compare Closing Prices') plotly.offline.plot(fig1, filename='compare-closing-prices') # Stacking the stocks on a single plot #figstack = closing_df.iplot(fill=True, asFigure=True, title="Tech Giants Closing Price", filename = 'stacked closing prices') closing_df_2["Date"] = closing_df_2.index.date closing_df_2.set_index("Date", drop=True, inplace=True) figstack = closing_df_2.iplot(fill=True, asFigure=True, title="Tech Giants Closing Price") plotly.offline.plot(figstack, filename='stacked closing prices') ### CORRELATION ANALYSIS ###