NAME
Finance::YahooQuote - Get stock quotes from Yahoo! Finance
SYNOPSIS
use Finance::YahooQuote;# setting TIMEOUT and PROXY is optional$Finance::YahooQuote::TIMEOUT = 60;$Finance::YahooQuote::PROXY = "http://some.where.net:8080";@quote = getonequote $symbol; # Get a quote for a single symbol@quotes = getquote @symbols; # Get quotes for a bunch of symbolsuseExtendedQueryFormat(); # switch to extended query formatuseRealtimeQueryFormat(); # switch to real-time query format@quotes = getquote @symbols; # Get quotes for a bunch of symbols@quotes = getcustomquote(["DELL","IBM"], # using custom format["Name","Book Value"]); # note array refs
DESCRIPTION
This module gets stock quotes from Yahoo! Finance. The getonequote function will return a quote for a single stock symbol, while the getquote function will return a quote for each of the stock symbols passed to it. getcustomquote allows to specify a format other than the default to take advantage of the extended range of available information.
The download operation is efficient: only one request is made even if several symbols are requested at once. The return value of getonequote is an array, with the following elements:
0 Symbol1 Company Name2 Last Price3 Last Trade Date4 Last Trade Time5 Change6 Percent Change7 Volume8 Average Daily Vol9 Bid10 Ask11 Previous Close12 Today's Open13 Day's Range14 52-Week Range15 Earnings per Share16 P/E Ratio17 Dividend Pay Date18 Dividend per Share19 Dividend Yield20 Market Capitalization21 Stock Exchange
If the extended format has been selected, the following fields are also retrieved:
22 Short ratio23 1yr Target Price24 EPS Est. Current Yr25 EPS Est. Next Year26 EPS Est. Next Quarter27 Price/EPS Est. Current Yr28 Price/EPS Est. Next Yr29 PEG Ratio30 Book Value31 Price/Book32 Price/Sales33 EBITDA34 50-day Moving Avg35 200-day Moving Avg
If the real-time format has been selected, the following fields are also retrieved:
36 Ask (real-time)37 Bid (real-time)38 Change in Percent (real-time)39 Last trade with time (real-time)40 Change (real-time)41 Day range (real-time)42 Market-cap (real-time)
The getquote function returns an array of pointers to arrays with the above structure.
The getonequote function returns just one quote, rather than an array. It returns a simple array of values for the given symbol.
The setQueryString permits to supply a new query string that will be used for subsequent data requests.
The useExtendedQueryFormat and useRealtimeQueryFormat are simpler interfaces which append symbols to the default quote string, as detailed above.
The getcustomquote returns an array of quotes corresponding to values for the symbols supplied in the first array reference, and the custom fields supplied in the second array reference. Here the custom fields correspond to the 'named' fields of the list below.
Beyond stock quotes, Finance::YahooQuote can also obtain quotes for currencies (from the Philadephia exchange -- however Yahoo! appears to have stopped to support the currency symbols in a reliable manner), US mutual funds, options on US stocks, several precious metals and quite possibly more; see the Yahoo! Finance website for full information. Finance::YahooQuote can be used for stocks from the USA, Canada, various European exchanges, various Asian exchanges (Singapore, Taiwan, HongKong, Kuala Lumpur, ...) Australia and New Zealand. It should work for other markets supported by Yahoo.
You may optionally override the default LWP timeout of 180 seconds by setting $Finance::YahooQuote::TIMEOUT to your preferred value.
You may also provide a proxy (for the required http connection) by using the variable $Finance::YahooQuote::PROXY. Furthermore, authentication-based proxies can be used by setting the proxy user and password via the variables $Finance::YahooQuote::PROXYUSER and $Finance::YahooQuote::PROXYPASSWD.
Two example scripts are provided to help with the mapping a stock symbols as well as with Yahoo! Finance server codes. The regression tests scripts in the t/ subdirectory of the source distribution also contain simple examples.
The available custom fields
The following list contains all the available data fields at Yahoo! along with the corresponding format string entry:
Symbol sName nLast Trade (With Time) lLast Trade (Price Only) l1Last Trade Date d1Last Trade Time t1Last Trade Size k3Change and Percent Change cChange c1Change in Percent p2Ticker Trend t7Volume vAverage Daily Volume a2More Info iTrade Links t6Bid bBid Size b6Ask aAsk Size a5Previous Close pOpen oDay's Range m52-week Range wChange From 52-wk Low j5Pct Chg From 52-wk Low j6Change From 52-wk High k4Pct Chg From 52-wk High k5Earnings/Share eP/E Ratio rShort Ratio s7Dividend Pay Date r1Ex-Dividend Date qDividend/Share dDividend Yield yFloat Shares f6Market Capitalization j11yr Target Price t8EPS Est. Current Yr e7EPS Est. Next Year e8EPS Est. Next Quarter e9Price/EPS Est. Current Yr r6Price/EPS Est. Next Yr r7PEG Ratio r5Book Value b4Price/Book p6Price/Sales p5EBITDA j450-day Moving Avg m3Change From 50-day Moving Avg m7Pct Chg From 50-day Moving Avg m8200-day Moving Avg m4Change From 200-day Moving Avg m5Pct Chg From 200-day Moving Avg m6Shares Owned s1Price Paid p1Commission c3Holdings Value v1Day's Value Change w1,Holdings Gain Percent g1Holdings Gain g4Trade Date d2Annualized Gain g3High Limit l2Low Limit l3Notes n4Last Trade (Real-time) with Time k1Bid (Real-time) b3Ask (Real-time) b2Change Percent (Real-time) k2Change (Real-time) c6Holdings Value (Real-time) v7Day's Value Change (Real-time) w4Holdings Gain Pct (Real-time) g5Holdings Gain (Real-time) g6Day's Range (Real-time) m2Market Cap (Real-time) j3P/E (Real-time) r2After Hours Change (Real-time) c8Order Book (Real-time) i5Stock Exchange x
FAQs
How can one figure out the format string?
Provided a My Yahoo! (http://my.yahoo.com) account, go to the following URL:
http://edit.my.yahoo.com/config/edit_pfview?.vk=v1
Viewing the source of this page, you will come across the section that defines the menus that let you select which elements go into a particular view. The <option> values are the strings that pick up the information described in the menu item. For example, Symbol refers to the string "s" and name refers to the string "l". Using "sl" as the format string, we would get the symbol followed by the name of the security.
The example script examine_server.sh shows this in some more detail and downloads example .csv files using GNU wget.
What about different stock symbols for the same corporation?
This can be issue. For the first few years, Yahoo! Finance's servers appeared to be cover their respective local markets. E.g., the UK-based servers provided quotes for Europe, the Australian one for the Australia and New Zealand and so on. Hence, one needed to branch and bound code and map symbols to their region's servers.
It now appears that this is no longer required, which is good news as it simplifies coding. However, some old symbols are no longer supported -- yet other, and supported, codes exist for the same company. For example, German stocks used to quoted in terms or their cusip-like 'WKN'. The main server does not support these, but does support newer, acronym-based symbols. The example script examine_server.sh helps in finding the mapping as e.g. from 555750.F to DTEGN.F for Deutsche Telekom.
COPYRIGHT
Copyright 1998 - 2002 Dj Padzensky Copyright 2002 - 2007 Dirk Eddelbuettel
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
The information that you obtain with this library may be copyrighted by Yahoo! Inc., and is governed by their usage license. See http://www.yahoo.com/docs/info/gen_disclaimer.html for more information.
AUTHOR
Dj Padzensky ("[email protected]"), PadzNet, Inc., wrote the original version. Dirk Eddelbuettel ("[email protected]") provided several extensions based on DJ's original work and is the current maintainer.
SEE ALSO
The Finance::YahooQuote home pages are found at http://www.padz.net/~djpadz/YahooQuote/ and http://dirk.eddelbuettel.com/code/yahooquote.html.
The smtm (Show Me The Money) program uses Finance::YahooQuote for a customisable stock/portfolio ticker and chart display, see http://dirk.eddelbuettel.com/code/smtm.html for more. The beancounter program uses it to store quotes in a SQL database, see http://dirk.eddelbuettel.com/code/beancounter.html.