Stocks data using Python (Example)
pandas_datareader
is a good package for downloading stocks data. It uses pandas
, which can be used to perform analysis. In this example, the stock price for Netflix is downloaded and plotted. Also, a rolling 60-days average is added to the plot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import pandas_datareader | |
# Download the Stock | |
s = pandas_datareader.get_data_yahoo("NFLX", start=datetime.datetime(2018,1,1)) | |
# Plot it | |
plt.figure(figsize=(10, 5)) | |
plt.plot(s["Adj Close"], label="NFLX") | |
plt.plot(s["Adj Close"].rolling(60).mean(), label="60 Days Rolling Mean") | |
plt.xticks(rotation=90) | |
plt.grid() | |
plt.legend() | |
plt.show() |
Note: remember to pip install pandas matplotlib pandas_datareader