Selvatech.com : in the jungle of financial I.T.

Monday, June 27, 2005

An in-depth examination of Yahoo! Financial Web Services

As I was building a statistical tools on stock quotes, I realized that I didn't find any reliable source or article describing the services provided by Yahoo! Finance.

I am using these services for three years now, and I have to admit that it is one of the best tool for anyone working on stock quotations (all over the world) and... it's free (massive argument for testing) !! There are so many data sources (Telekurs, Comstock...), that it's best to have a look and try to see wich company provides it.

All datas are available on web page (see
http://finance.yahoo.com/q?s=GE for a summary of financial information on stock code GE : General electric for example), some datas are available as Excel spreadsheet download, and, finally, some datas are available as "Web Services". Well, it's more a proprietary service on internet than a Web Services (no web service description file...).

I will go into details about 3 services : quotation service, index components service and historical data service.


Quotation Web Service

As you can see on http://finance.yahoo.com/q?s=GE page, there is a small "Download data" link. This link will download a CSV file using the hyperlink http://finance.yahoo.com/d/quotes.csv?s=GE&f=sl1d1t1c1ohgv&e=.csv .

The data received look like the following :

GE,34.74,"6/27/2005","1:25pm",-0.04,34.72,34.86,34.60,14050200

Let's try to understand how it works :

Obviously the GE parameter in the URL (s=GE) is related to the stock code, in fact on New Yorck Stock Exchange, General electric stocks are symbolized by GE code. You will notice that the quotation place is not showed. You can write comma separated stock quotes to retrieve several quotations at the same time. For example : http://finance.yahoo.com/d/quotes.csv?s=GE,MSFT&f=sl1d1t1c1ohgv&e=.csv .

Once the stock code is references, the f parameter is a long string composed of letters and figures. Strangely, I found no web site describing precisely these parameters. I found their meaning empirically :

aAska2Average Daily Volumea5Ask Size
bBidb2Ask (Real-time)b3Bid (Real-time)
b4Book Value b6Bid SizecChange & Percent Change
c1Quotation Net Changec3Commissionc6Change (Real-time)
c8After Hours Change (Real-time)dDividend/Shared1Last Trade Date
d2Trade DateeEarnings/Sharee1Error Indication (returned for symbol changed / invalid)
e7EPS Estimate Current Yeare8EPS Estimate Next Yeare9EPS Estimate Next Quarter
f6Float SharesgDay's LowhDay's High
j52-week Lowk52-week High g1Holdings Gain Percent
g3Annualized Gaing4Holdings Gaing5Holdings Gain Percent (Real-time)
g6Holdings Gain (Real-time)iMore Infoi5Order Book (Real-time)
j1Market Capitalizationj3Market Cap (Real-time)j4EBITDA
j5Change From 52-week Lowj6Percent Change From 52-week Lowk1Last Trade (Real-time) With Time
k2Change Percent (Real-time)k3Last Trade Sizek4Change From 52-week High
k5Percent Change From 52-week HighlLast Trade (With Time)l1Last Trade (Price Only)
l2High Limitl3Low LimitmDay's Range
m2Day's Range (Real-time)m350-day Moving Averagem4200-day Moving Average
m5Change From 200-day Moving Average m6Percent Change From 200-day Moving Averagem7Change From 50-day Moving Average
m8Percent Change From 50-day Moving AveragenNamen4Notes
oOpen pPrevious Closep1Price Paid
p2Change in Percentp5Price/Salesp6Price/Book
qEx-Dividend DaterP/E Ratior1Dividend Pay Date
r2P/E Ratio (Real-time)r5PEG Ratior6Price/EPS Estimate Current Year
r7Price/EPS Estimate Next YearsSymbols1Shares Owned
s7Short Ratiot1Last Trade Timet6Trade Links
t7Ticker Trendt81 yr Target PricevVolume
v1Holdings Valuev7Holdings Value (Real-time)w52-week Range
w1Day's Value Changew4Day's Value Change (Real-time)xStock Exchange
y Dividend Yield


The only web site giving this information (as far as I searched it) is http://www.gummy-stuff.org/Yahoo-data.htm.

It e querystring parameter (e for extension?) looks like being optional (e=.csv).

We will see later in this article how to retrieve quotation data from a VB.Net Application (ASP.Net or Windows Application). As said before, you can't declare the quotation place when you call the web service. In fact, the stock code contains this information. For General electric (GE), this is not obvious, but if you take a stock on the french market, L'Oreal for example, its code will be OR.PA where PA means Paris. Some companies can be quoted on several stock exchange, and each quotation is different. For example, let's take Microsoft shares : on XETRA Stock Exchange (Germany), its code is MSF.DE, the quotation is in Euro, and on NASDAQ, the code is MSFT ans the quotation in Dollars. Of course, to make things more difficult, codes are not standardized ! So you should pay the highest attention in choosing the Stock Symbol to use in the quotation web service. Unfortunately, Yahoo doesn't provide any web service for symbol lookup.

Indices components Web Service

This is probably the simplest web service provided, but it can be very helpful. It's goal is to provide a list of all stocks composing an indice : Dow Jones Industrial, Nasdaq 100, CAC40... These indices quotations are calculated as an average of its components quotation. This web service maintains the list of components (a huge work in itself) and their quotation.

Its call is very similar to the regular quotation service, as if you were adding all stock symbols in the querystring. This is web page of the service : http://finance.yahoo.com/q/cp?s=%5ENDX for Nasdaq 100 components which symbol is ^NDX. To download the information, we call http://finance.yahoo.com/d/quotes.csv?s=@%5ENDX&f=sl1d1t1c1ohgv&e=.csv where we recognize the parameters of the quotation web service. The result is a csv stream that can be considered as a web service and looks like :

AAPL,37.31,"6/28/2005","4:00pm",+0.21,37.49,37.59,37.17,12555196
ADBE,28.70,"6/28/2005","4:00pm",-0.14,29.05,29.05,28.25,7916337
ADSK,34.81,"6/28/2005","4:00pm",+0.86,34.00,34.92,33.49,2695397
ALTR,19.52,"6/28/2005","4:00pm",-0.19,20.00,20.00,19.41,9181970
AMAT,16.31,"6/28/2005","4:00pm",+0.08,16.36,16.42,16.24,16429051


However, this web service has a strange behavior depending on the URL called. For American indices, you have to deal with pagination : you can only get 50 stocks in your file. So, to download all data for Nasdaq 100, you have to call the service 6twice (there are 100 stocks composing the indice !). This is highly inefficient but understandable as a provider point of view. But what strikes me, is that it is not the same policy on other countries stock markets ! Considering French Yahoo, if you download the information from http://fr.old.finance.yahoo.com/d/quotes.csv?s=@^NDX&f=snl1d1t1c1ohgv&e=.csv , you will get the whole information with a single call !!!

Historical data Web Service

A list of historical quotations (and dividend payment) is available through a web service. This web service takes as parameters 2 dates , a stock symbol and a frequency (daily, weekly, monthlyor dividend only). In the case of weekly and monthly frequency, an average on each period is done.

At this URl , http://finance.yahoo.com/q/hp?s=GE&a=00&b=1&c=2004&d=05&e=28&f=2005&g=d, a list of daily quotations for General Electric is given from january 1st 2004 to june 28th 2005. The parameters are almost strightforward :

a : first date month (0-based array : january =0, february = 1,... december =11)
b : first date day
c : fist date year
d : last date month (0-based array : january =0, february = 1,... december =11)
e : last date day
f : last date year
g : frequency (d = daily, w = weekly, m = monthly, v = dividends only)

The URL to call as a web service is http://ichart.finance.yahoo.com/table.csv?s=GE&a=00&b=1&c=2004&d=05&e=28&f=2005&g=d&ignore=.csv

No pagination problem here, the result is a table with the first row describing the columns :

Date,Open,High,Low,Close,Volume,Adj. Close*
27-Jun-05,34.72,34.86,34.59,34.61,23402900,34.61
24-Jun-05,34.75,35.98,34.15,34.78,67540496,34.78
23-Jun-05,35.50,35.63,34.52,34.66,48926900,34.66
22-Jun-05,36.20,36.34,35.68,35.72,29200400,35.50

Brightly, Yahoo guys provides us with the Adjusted Close which takes into consideration dividends payment and stock splits.