Knowledge Base | How to Load Historical Stock Prices from Yahoo Finance to CSV

Contents

Historical Prices at Yahoo Finance

Yahoo Finance provides data for a lot of exchanges.

You may open http://finance.yahoo.com/, search a ticker like YHOO, and click the 'Historical Data' tab.

You may use URLs like https://finance.yahoo.com/quote/YHOO/history to open pages with historical prices directly.

You may download the historical prices to a CSV file using the 'Download Data' link above the Volume column.

You may download data for the required selected period.
Unfortunately, Yahoo disabled loading historical prices using download utilities in May 2017.

Undocumented URLs to Download Historical Prices from Yahoo Finance

Yahoo Finance uses a web service to load historical stock and currency prices into web pages.

You may use specialized download and parser utilities like gwebcmd to download and convert JSON data to CSV.

For example, to get daily historical prices use the command:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=2y&interval=1d&indicators=quote&includeTimestamps=true" ^
    yhoo.csv /rootpath=*.*.timestamp,*.*.*.quote,*.*.*.unadjquote

To get weekly historical prices:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=5y&interval=1wk&indicators=quote&includeTimestamps=true" ^
    yhoo-weekly.csv /rootpath=*.*.timestamp,*.*.*.quote,*.*.*.unadjquote

To get monthly historical prices:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=max&interval=1mo&indicators=quote&includeTimestamps=true; ^
    yhoo-monthly.csv /rootpath=*.*.timestamp,*.*.*.quote,*.*.*.unadjquote

To get 1-minute intraday prices:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=1d&interval=1m&indicators=quote&includeTimestamps=true" ^
    yhoo-1.csv

To get 5-minute intraday prices:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=5d&interval=5m&indicators=quote&includeTimestamps=true" ^
    yhoo-5.csv

To get 15-minute intraday prices:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=5d&interval=15m&indicators=quote&includeTimestamps=true" ^
    yhoo-15.csv

To get 60-minute intraday prices:

gwebcmd webtocsv ^
    "https://query1.finance.yahoo.com/v7/finance/chart/YHOO?range=1mo&interval=60m&indicators=quote&includeTimestamps=true" ^
    yhoo-15.csv

gwebcmd in the webtocsv mode loads web data (JSON, XML, HTML, CSV) and converts the data to CSV.

Specify the /rootpath=*.*.timestamp,*.*.*.quote,*.*.*.unadjquote parser parameter that points to the JSON roots of historical prices.

You may load historical prices for currencies. Just use tickers like GBPUSD=X.

Loading Historical Prices from Yahoo Finance with Batch Files

Create a text file like 'task.txt' and place tickers one by line like:

TICKERS.TXT
AAPL
FB
GOOGL
YHOO

Create a batch file like 'load.cmd' with the following commands:

LOAD.CMD
@echo off

@for /F %%i in (tickers.txt) do (
    gwebcmd webtocsv ^
        "https://query1.finance.yahoo.com/v7/finance/chart/%%i?range=2y&interval=1d&indicators=quote&includeTimestamps=true" ^
        %%i.CSV /delay=200 /echoOutputFileName /rootpath=*.*.timestamp,*.*.*.quote,*.*.*.unadjquote
)

Run it. You will see the result:

C:>load.cmd
AAPL.CSV - 504 rows
FB.CSV - 504 rows
GOOGL.CSV - 504 rows
YHOO.CSV - 504 rows

Pay attention to the /delay parameter. Use the delay to avoid banning your IP due to frequent multiple automatic requests.

Downloading Historical Prices from Yahoo Finance using Market.csv

Market.csv is a specialized tool for loading data from Yahoo Finance, Google Finance, and MSN Money.

You place the required tickers to a file like tickers.txt.

TICKERS.TXT
^VIX
SPY
126.1.AAPL.NAS
NYSE:BRK.B
RIO.L
GBPUSD

Then you execute commands to download data using the required data providers:

C:\MarketData
market.csv.exe download YahooHistoricalPricesDaily
market.csv.exe download YahooHistoricalPricesWeekly
market.csv.exe download YahooHistoricalPricesMonthly
market.csv.exe download YahooIntradayPrices1m
market.csv.exe download YahooIntradayPrices5m
market.csv.exe download YahooIntradayPrices15m
market.csv.exe download YahooIntradayPrices60m

The tool downloads data, archives the data to zip files and converts the data to CSV.

You may get results in the output files like YahooHistoricalPricesDaily.csv, YahooHistoricalPricesWeekly.csv, etc.

Moreover, Market.csv includes ready-to-use SQL codes and format files to import CSV data into a Microsoft SQL Server database.

Downloads

Products for Traders and Investors
WEB.CSV
The app loads data from the web (HTML, XML, JSON, and CSV) into CSV
Version: 4.7 | 11/03/2017 | 1.4MB | Home | What's New | Editions
Download
MARKET.CSV
The app loads data from Yahoo Finance, Google Finance, and MSN Money to CSV and SQL Server
Version: 2.7 | 12/13/2017 | 0.9MB | Home | What's New | Edition Comparison
Download

Disclaimer

Yahoo Finance is a logo and registered trademark of Yahoo! Inc.