In this tutorial, we are going to learn how to pull stock price (both live and historical) with Python.

Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn





Source Code:

import datetime
import pandas as pd
from pandas_datareader import data

pd.set_option('display.max_columns', 100)
pd.set_option('display.max_rows', 150)
pd.set_option('display.max_colwidth', 150)
pd.set_option('display.width', 120)
pd.set_option('expand_frame_repr', True)

# stockData = data.get_quote_yahoo(tickers)
# print(stockData)


# tickers = ['MSFT', 'AAPL', 'GOOG', 'TSLA']
# end_date = datetime.datetime.today()
# start_date = end_date - datetime.timedelta(days=180)
# historicalPrices = data.DataReader(tickers, start=start_date, end=end_date, data_source='yahoo')
# print(historicalPrices)

tickers = ['MSFT', 'AAPL', 'GOOG', 'TSLA']
start_date = '2020-1-1'
end_date = '2020-1-31'

for ticker in tickers:
    historicalPrices = data.DataReader(ticker, start=start_date, end=end_date, data_source='yahoo')
    print(historicalPrices)