Visualizing Tech Stocks

import pandas as pd
import numpy as np
import pandas_datareader as web
import matplotlib.pyplot as plt
%matplotlib inline
symbols = ["MSFT", "AMZN", "AAPL", "GOOG", "FB"]
start_date = "2019-01-1"
end_date = "2019-07-1"
stock_data = web.get_data_yahoo(symbols,start_date,end_date)
print(stock_data)
print(stock_data['Adj Close'])

stock_data_closing_prices = stock_data['Adj Close']
stock_data_closing_prices.plot()
plt.xlabel("Date")
plt.ylabel("Adjusted Closing Price Over Time")
plt.title("Tech Stocks Adjusted Price")
plt.show()

stock_data_daily_returns = stock_data['Adj Close'].pct_change()
stock_data_daily_returns.plot()
plt.xlabel("Date")
plt.ylabel("ROR")
plt.title("Daily Simple Rate of Return Over time")
plt.figure(figsize=(16,9))
plt.show()

fig = plt.figure(figsize=(15,15))
ax1 = fig.add_subplot(321)
ax2 = fig.add_subplot(322)
ax3 = fig.add_subplot(323)
ax4 = fig.add_subplot(324)
ax5 = fig.add_subplot(325)
ax1.plot(stock_data['Adj Close']['AMZN'].pct_change())
ax1.set_title("Amazon")
ax2.plot(stock_data['Adj Close']['AAPL'].pct_change())
ax2.set_title("Apple")
ax3.plot(stock_data['Adj Close']['FB'].pct_change())
ax3.set_title("Facebook")
ax4.plot(stock_data['Adj Close']['GOOG'].pct_change())
ax4.set_title("Google")
ax5.plot(stock_data['Adj Close']['MSFT'].pct_change())
ax5.set_title("Microsoft")
plt.tight_layout()
plt.show()

mean = stock_data_daily_returns.mean()
mean.keys()
h = []
for key in mean.keys():
    h.append(mean[key])
x_pos = np.arange(len(mean.keys()))
plt.bar(x_pos,h)
plt.xticks(x_pos, mean.keys())
plt.xlabel("Tech Stocks")
plt.ylabel("Daily mean")
plt.title("Daily mean rate of return")
plt.show()

variance = stock_data_daily_returns.var()
variance.keys()
v = []
for key in variance.keys():
    v.append(variance[key])
x_pos = np.arange(len(variance.keys()))
plt.bar(x_pos,v)
plt.xticks(x_pos, variance.keys())
plt.xlabel("Tech Stocks")
plt.ylabel("Variance")
plt.title("Daily Variance")
plt.show()

standev = stock_data_daily_returns.std()
standev.keys()
s = []
for key in standev.keys():
    s.append(standev[key])
x_pos = np.arange(len(standev.keys()))
plt.bar(x_pos,s)
plt.xticks(x_pos, standev.keys())
plt.xlabel("Tech Stocks")
plt.ylabel("Standard deviation")
plt.title("Daily Standard deviation")
plt.show()

Corr = stock_data_daily_returns.corr()
print(Corr)

Giving feedback for the first time? AWESOME! Check out this video for a boost of confidence: How to Review Someone Else’s Code
Feel free to remove this message before posting.

Cheers!
—Codecademy Community Managers