Using Yahoo! Financial Stock Quotes

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

Access Stock Quotes On-Line - Mark Alexander Bain
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

Mark Alexander Bain - Mark Alexander Bain is a writer, Mo Bro and consultant for all aspects of software development at dsquared. He has also written regularly ...

rss
Advertisement
Advertisement
Advertisement