How to download stock price and volumn data from yahoo finance to local machine?

  Pandas, Python, Stocks

The first step in using stock data for financial analysis is to download price data from yahoo Finance. Below is a very simple example for downloading data.

import yfinance as yf
import pandas as pd
startDay="2020-06-18"
endDay="2020-06-20"

fnlist='nasdqIntheUSAMostActiveStocks.txt' #symbols
fns=pd.read_csv(fnlist)
toPath='NASDQ/'

for fn0 in fns.Symbols:
    stockName=fn0.replace(' ','')
    toFile=toPath+stockName+'.csv'
    toFile=toFile.replace(' ','')
    data = yf.download(stockName, start=startDay, end=endDay)
    data.to_csv(toFile)