Download stock data using Python yahoo finance API plugin

Goal here is to get historical (time series) stock price with respect to time.

The approach recommended for this is to use python yahoo finance API plugin – download function to get data.

Below example extract stock data from given symbol using yahoo finance, market ‘Close’ price and save it to panda dataframe.

import yfinance as yf
import pandas as pd
import datetime

symbol = ['AAPL', 'MSFT', 'DIS', 'JNJ', 'AXP', 'CVX']
data = pd.DataFrame(columns=symbol)
start_date = '2005-01-01'

for ticker in symbol:
    data[ticker] = yf.download(ticker,  start_date, datetime.datetime.now())['Close']

data.plot()
Download stock data using Python yahoo finance API plugin

Leave a Reply

Your email address will not be published. Required fields are marked *