Suite101

Using Yahoo! Financial Stock Quotes

How to Access and Use On-Line Financial Data from Yahoo!

© Mark Alexander Bain

Oct 5, 2008
Access Stock Quotes On-Line, Mark Alexander Bain
Yahoo! Financial stock quotes are free, on-line and can be accessed either via the Yahoo! web site or downloaded into Microsoft Excel or OpenOffice.org Calc

Yahoo! Finance is a free and easy to use on-line financial service which was used by more than 18 million people in May 2008 alone (according to the Internet analysis company comScore). This article will look at how anyone can obtain stock quotes from the Yahoo! Finance web site, and how to load those stock quotes into applications such as Microsoft Excel and OpenOffice.org Calc.

Obtaining Yahoo! Finance Stock Quotes for a Company

For anyone with Internet access the easiest way to obtain stock quotes is to go directly to the Yahoo! Finance web site at

http://finance.yahoo.com. Once there the user can get the current stock quote of any company in one of two ways:

  • enter the Yahoo! acronym for the company into the Yahoo! Finance text box and then click on "GET QUOTES"
  • start typing the company name into the Yahoo! Finance text box - it will then display a list of all possible company matches

For instance if micro is typed into the box then the suggestions will include:

  • MSFT Microsoft Corporation NASDAQ
  • JAVA Sun Microsystems Inc NASDAQ
  • AMD Advanced Micro Devices Inc. NYSE

It's then just a matter of selecting the correct company and the user will see that Microsoft (for instance) is currently up 0.19% at 26.30.

Obtaining Yahoo! Finance Stock Quotes for Multiple Companies

Examining the stock quote for an individual company is very informative, but if there are a number of companies to be viewed then this can be rather time consuming; therefore it's useful to know that it is possible to view the stock quotes of more than one company at the same time - and that's by entering the acronym for each company into the Yahoo! Finance text box and separating them using commas, for example:

RHT,MSFT,NOVL

This time, as well as seeing the Microsoft stock quotes, the user would see that Red Hat is down 4.19% at 14.65 while Novell is up 1.19% at 5.00.

Accessing the Yahoo! Finance Stock Quotes Directly

Having seen how to access stock quotes using the Yahoo! Finance web interface, it's worth noting that the current stock quotes can also be accessed directly by entering the correct URL into a web browser, for example:

http://finance.yahoo.com/q/cq?d=v1&s=RHT,MSFT,NOVL

Loading Yahoo! Finance Stock Quotes into Microsoft Excel or OpenOffice.org Calc

Users of Microsoft Excel or OpenOffice.org Calc can load the Yahoo! Finance stock quotes in one of three ways:

  • click on the "Download to Spreadsheet" link (displayed below the requested companies' stock quotes)
  • enter the URL for the CSV file that the "Download to Spreadsheet" link points to, for example:
    http://download.finance.yahoo.com/d/quotes.csv?s=RHT,MSFT,NOVL&f=sl1c1d1&e=.csv
    where f stands for the fields to be displayed (in this case: s - symbol; l1 - last price; c1 - change; d1 = last date)
  • run a macro to load the data automatically

A Microsoft Excel Macro for Loading Yahoo! Finance Stock Quotes

The code for a Microsoft Excel that will download the Yahoo! Finance stock quotes is fairly simple, consisting of two subroutines; one to define the companies and fields, the other to format the URL to be used:

Sub getStocks ()
Dim companies As String
Dim fields As String
companies = "RHT,MSFT,NOVL"
fields = "sl1c1d1" ' symbol, last price, change and date
downloadStocks (companies, fields)
End Sub
Sub downloadStocks (companies As String, fields As string)
Dim url As String
url = "http://download.finance.yahoo.com/d/quotes.csv?" _
& "s=" & companies _
& "&f=" & fields & "&e=.csv"
Workbooks.Open Filename:= url
End Sub

An OpenOffice.org Calc Macro for Loading Yahoo! Finance Stock Quotes

The OpenOffice.org Calc code is slightly more complex than the Microsoft Excel code - the getStocks subroutine would be identical, but the downloadStocks subroutine would not (although it does the same job):

Sub getStocks ()
Dim companies As String
Dim fields As String
companies = "RHT,MSFT,NOVL"
fields = "sl1c1d1" ' symbol, last price, change and date
downloadStocks (companies, fields)
End Sub
sub downloadStocks (companies as String, fields as string)
dim url as string
dim doc
dim propertyValue(0) as new com.sun.star.beans.PropertyValue
url = "http://download.finance.yahoo.com/d/quotes.csv?" _
& "s=" & companies _
& "&f=" & fields & "&e=.csv"
propertyvalue(0).name = "FilterOptions"
propertyvalue(0).value ="44" 'csv
doc = stardesktop.loadcomponentfromurl _
(url, "_blank", 0, propertyvalue)
end sub

Conclusion

Yahoo! Finance stock quotes provide an easy to access and free data source; and the ability to either view the information on-line or to download it for future use make it an invaluable tool.

Additional Reading

An Introduction to Google Finance

Accessing Yahoo! Finance from PHP


The copyright of the article Using Yahoo! Financial Stock Quotes in Computer Programming is owned by Mark Alexander Bain. Permission to republish Using Yahoo! Financial Stock Quotes in print or online must be granted by the author in writing.


Access Stock Quotes On-Line, Mark Alexander Bain
Yahoo! Finance Company Look-Up, Mark Alexander Bain
A Snapshot of the Market, Mark Alexander Bain
   


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo