Importing Financial Data

Category : Research

Importing Financial Data

Download the PDF from SSRN.
Examples: fetchyahookeystats and fetchyahooquotes.


This note describes two programs fetchyahooquotes and fetchyahookeystats, which import historical financial data and key current financial statistics from Yahoo! Finance.
Keywords: Finance, financial data, stocks, ETF, historical data


Yahoo! Finance offers the public large amounts of financial and economic data. Often, small amounts of this data can be imported into Stata without much difficulty. However, to be able to use this data in econometric analysis, some automated download procedure may prove useful. Below, we describe two programs, fetchyahooquotes and fetchyahookeystats, that automate the process of importing financial data from Yahoo! Finance.

These two programs are useful for instructors who work with financial data during their lectures and need quick access to current data. They are especially useful for finance project assignments. Students do not have to spend long hours to download data into Excel spreadsheets and to merge them into portfolios.These programs are also important for researchers. Many teaching universities do not have subscriptions to costly finance databases.
While Yahoo! Finance is not a substitute, it is a useful alternative. Finally, they are important for investors. fetchyahooquotes and fetchyahookeystats make financial data access fast and easy.

The fetchyahooquotes command is used to download time series of the more common financial statistics of multiple financial instruments. Thus, one could download the daily opening and closing prices over the past ten years of IBM and Microsoft stocks, for example.

fetchyahookeystats is similar to fetchyhooquotes, but downloads only the current day’s key financial statistics for multiple financial instruments (for example, today’s opening and closing prices for IBM and Microsoft).

The fetchyahooquotes and fetchyahookeystats commands


  • namelist is a list of ticker symbols to be downloaded from Yahoo! Finance’s API. Ticker symbols are separated by spaces. The ticker symbol will become part of the variable name. Regardless of whether the symbol includes special characters, ticker is typed (including the special character) exactly as it is used by Yahoo! Finance’s API. Any special characters will be replaced for the variable name with underscores since they are not allowed as Stata variable names.
  • freq(d/w/m/v) specifies the frequency of the historic price including (d)daily, (w)weekly, (m)monthly or (v)dividends only. Note: If the frequency is either daily, weekly or monthly then the variable with the symbol name is the adjusted closing price. If the frequency is to include only the dividends then the symbol name is the dividend payment.
  • chg(ln/per/sper) is the periodic return. Three different periodic changes can be calculated for the adjusted closing price; natural log difference, percentage change and symmetrical percentage change. The change is based on the continuous trading assumption. Thus, even though the tsset is the date (which may contain gaps), returns are calculated assuming there are no gaps in the data.
  • start(string) is the starting date for the prices (i.e. 1mar2010) in DMY format.
  • end(string) is the ending date for the prices (i.e. 23feb2011) in DMY format.
  • ff3 Fama/French daily factors are downloaded from “Kenneth R. French – Data Library“.
  • field(string) for fetchyahooquotes, is the variables to download in addition to the adjusted close and the date: These include: (o) open, (h) high, (l) low, (c) close, (v) volume.
  • field((string) for fetchyahookeystats, is the Yahoo! Finance’s specific field code corresponding to a key statistic. These include (but are not limited to): a (Ask), l1 (Last Trade Price), b (Bid), m3 (50-Day Moving Average), b4 (Book Value), m4 (200-Day Moving Average), c (Percent Change), n (Name), c1 (Change), o (Open), d (Dividend per Share), p (Previous Close), d1 (Last Trade Date), p5 (Price/Sales), e (Earning per Share), p6 (Price/Book), f6 (Float Shares), q (Ex-Dividend Date), g (Day’s Low), r (Price/Earnings), h (Day’s High), s (Symbol), j (52-Week Low), s7 (Short Ratio), j1 (Market Capitalization), v (Volume), j4 (EBITDA), x (Exchange), k (52-Week High) and y (Dividend Yield).
  • ff3 whether to download daily Fama-French three factors and merge them (by date) to the existing data in memory.
  • merge is whether to merge with the data that is already in the memory.
  • allatonce whether to download all symbols at once (limit to 50 by Yahoo! Finance and URL character length).

How to install
Then, click on the fetchyahooquotes and fetchyahookeystats links and then “click here to install”.

Example #1: Single company historic share prices

This example uses fetchyahooquotes to import the adjusted daily closing price of Microsoft shares from the beginning of 2010 to the end of 2015. The program also calculates the log difference change of the daily adjusted closing share prices.

Screen Shot 2016-08-13 at 3.02.21 PM

Example #2: Multiple companies’ historic share prices

This example downloads monthly historical data on the closing share prices of Microsoft and IBM, and computes the log difference changes. The monthly data is actually the data for the first day of trading in the month.

Screen Shot 2016-08-13 at 3.05.52 PM

Example #3: Importing key statistics for multiple companies

This example uses fetchyahookeystats to download today’s key statistics for IBM, Google, BMW and the S\&P-500.

Screen Shot 2016-08-13 at 3.10.24 PM