Getting Market Stock Data from Yahoo Finance is not difficult with Python Module – Pandas.
To follow this tutorial at least you know how to run python code.
In this tutorial, I use:
-Python 3.6.9 (default, Dec 8 2021, 21:08:43)
-Matplotlib-3.3.4
-Pandas 1.1.5
-Xubuntu 18.04
and Vim for text editor
Before you start, make sure you are connected to the Internet.
If you don’t have Python, Matplotlib and Pandas, you can install it from Linux Terminal with commands below:
$ sudo apt-get install python3 $ pip3 install matplotlib $ pip3 install pandas
The source codes:
import datetime as dt import matplotlib.pyplot as plt import pandas as pd import pandas_datareader.data as web start=dt.datetime(2010,1,1) end=dt.datetime(2022,4,22) df1 = web.DataReader('MSFT','yahoo',start,end) df2 = web.DataReader('AAPL','yahoo',start,end) plt.plot(df1.Close) plt.plot(df2.Close) plt.legend(['MSFT','APPL']) plt.grid() plt.xlabel('Year') plt.ylabel('Price (USD)') plt.title('STOCK PRICE COMPARISON MICROFSOFT AND APPLE \n JAN 2010 - APR 2022') plt.show()
You can run it in Linux Terminal, Python IDLE, Jupiter notebook or any Python environtment.
Leave a comment