Download historical data from Yahoo Finance

Table of Contents


The majority of people use Yahoo Finance to obtain updated quotes for traded securities all around the world. However, it can be a useful source of financial data also for research purposes. The trick is to be able to easily obtain historical series of prices.


The first problem is to identify the ticker symbol of the desired securities. The ticker symbol is an unique string that identifies each security. A global selection of tickers is available as an Excel file from investexcel.

For the New York stock exchange (NYSE), the updated list of tickers can be automatically downloaded in CSV format using

wget http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=nyse&render=download

I use wget but one can directly past the URL in the adress bar of any browser. Replace 'nyse' with 'nasdaq' to obtain the list of security traded on NASDAQ. The obtained file lists:

  1. the ticker symbol
  2. the name of the company
  3. the price of the last transaction
  4. the market capitalization,
  5. the IPO year
  6. the Sector as defined by the stock exchange,
  7. the Industry, a further division of the Sectors
  8. the link to company page on the stock exchange website

Obtain historical data

Once the ticker of the interesting security is know, the data can be downloaded using the base URL http://real-chart.finance.yahoo.com/, and adding the required information, according to the following structure

wget http://real-chart.finance.yahoo.com/table.csv?s=[ticker]&[options]

where [ticker] is mandatory and is the ticker of the desired security and [options] is a list of name=value pairs separated by & taken from th following list:

The "from month"
The "from day" (two digits)
The "from year"
The "to month"
The "to day" (two digits)
The "to year"
the frequency: d for daily, m for monthly, y for yearly, (v for dividend)

For instance, to obtain the daily prices of the General Eletricks (GE) from the 2nd of January 1962 to the 22nd of February 2016, use

wget http://real-chart.finance.yahoo.com/table.csv?s=GE&a=00&b=2&c=1962&d=02&e=22&f=2016&g=d

The data are saved in a file named table.csv and apparently this name cannot be modified, but see below. Price files contain the following comma separated fields:

  1. Date
  2. Open
  3. High
  4. Low
  5. Close
  6. Volume
  7. Adj Close


First of all, it is annoying that the data are always saved in the same file. We can overcome this difficulty using the option -O of wget. Second, we generally want to download data about several securities at once. For instance, in order to download the price data at daily frequency for all NYSE traded companies in the Technology sector we can proceed as follows (from the command line). First, we obtain the list of traded comapnies and we save them in the file companies.txt

wget http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=nyse&render=download -O companies.txt;

Next, from the downloaded file, we obtain the list of tickers of the Technology sector and save them in the env variable ticks

ticks=$( gawk -F, '{ if($6=="\"Technology\""){ gsub(/"/,"",$1); print $1} }' companies.txt )

Finally, we cicle over all ticks and download the price data

for tick in $ticks; do
    wget "http://real-chart.finance.yahoo.com/table.csv?s=${tick}&a=00&b=1&c=2015&d=12&e=31&f=2015&g=d" -O ${tick}.txt

The procedure above is available in the example file.

Author: Giulio Bottazzi

Created: 2017-01-04 Wed 19:11