Finance::YahooQuote is aPerl module to retrieve stock (and otherquotes) fromYahoo! Finance. A veryvast number of fields can be retrieved, the full list comprises price andvolume information (delayed from the exchanges; real-time from ECNs) as wellas valuation and balance-sheet items. See below for the full set ofattributes available sinceversion 0.20 ofFinance::YahooQuote.
Several functions are provided. Thegetquote functionreturns an array of pointers to arrays with the above structure. Thegetonequote function returns just one quote, rather than anarray. It returns a simple array of values for the given symbol. ThesetQueryString permits to supply a new query string thatwill be used for subsequent data requests. TheuseExtendedQueryFormat anduseRealtimeQueryFormat are simpler interfaces which appendsymbols to the default quote string, as detailed above. Thegetcustomquote returns an array of quotes corresponding tovalues for the symbols supplied in the first array reference, and the customfields supplied in the second array reference. Here the custom fieldscorrespond to the 'named' fields of the list below.
The download operation is efficient: only one request is made even if severalsymbols are requested at once. The return value ofgetonequote, if the backwards-compatible default settingsare used, is an array with the following elements:
0 Symbol 1 Company Name 2 Last Price 3 Last Trade Date 4 Last Trade Time 5 Change 6 Percent Change 7 Volume 8 Average Daily Vol 9 Bid 10 Ask 11 Previous Close 12 Today's Open 13 Day's Range 14 52-Week Range 15 Earnings per Share 16 P/E Ratio 17 Dividend Pay Date 18 Dividend per Share 19 Dividend Yield 20 Market Capitalization 21 Stock ExchangeThe full list of available fields, along with their query format symbols isIf the extended format has been selected, the following fields are alsoretrieved:
22 Short ratio 23 1yr Target Price 24 EPS Est. Current Yr 25 EPS Est. Next Year 26 EPS Est. Next Quarter 27 Price/EPS Est. Current Yr 28 Price/EPS Est. Next Yr 29 PEG Ratio 30 Book Value 31 Price/Book 32 Price/Sales 33 EBITDA 34 50-day Moving Avg 35 200-day Moving AvgIf the real-time format has been selected, the following fields are alsoretrieved:
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)
Symbol s Name n Last Trade (With Time) l Last Trade (Price Only) l1 Last Trade Date d1 Last Trade Time t1 Last Trade Size k3 Change and Percent Change c Change c1 Change in Percent p2 Ticker Trend t7 Volume v Average Daily Volume a2 More Info i Trade Links t6 Bid b Bid Size b6 Ask a Ask Size a5 Previous Close p Open o Day's Range m 52-week Range w Change From 52-wk Low j5 Pct Chg From 52-wk Low j6 Change From 52-wk High k4 Pct Chg From 52-wk High k5 Earnings/Share e P/E Ratio r Short Ratio s7 Dividend Pay Date r1 Ex-Dividend Date q Dividend/Share d Dividend Yield y Float Shares f6 Market Capitalization j1 1yr Target Price t8 EPS Est. Current Yr e7 EPS Est. Next Year e8 EPS Est. Next Quarter e9 Price/EPS Est. Current Yr r6 Price/EPS Est. Next Yr r7 PEG Ratio r5 Book Value b4 Price/Book p6 Price/Sales p5 EBITDA j4 50-day Moving Avg m3 Change From 50-day Moving Avg m7 Pct Chg From 50-day Moving Avg m8 200-day Moving Avg m4 Change From 200-day Moving Avg m5 Pct Chg From 200-day Moving Avg m6 Shares Owned s1 Price Paid p1 Commission c3 Holdings Value v1 Day's Value Change w1, Holdings Gain Percent g1 Holdings Gain g4 Trade Date d2 Annualized Gain g3 High Limit l2 Low Limit l3 Notes n4 Last Trade (Real-time) with Time k1 Bid (Real-time) b3 Ask (Real-time) b2 Change Percent (Real-time) k2 Change (Real-time) c6 Holdings Value (Real-time) v7 Day's Value Change (Real-time) w4 Holdings Gain Pct (Real-time) g5 Holdings Gain (Real-time) g6 Day's Range (Real-time) m2 Market Cap (Real-time) j3 P/E (Real-time) r2 After Hours Change (Real-time) c8 Order Book (Real-time) i5 Stock Exchange x
Beyond stock quotes,Finance::YahooQuote can also obtainquotes for currencies (from the Philadephia exchange -- however Yahoo!appears to have stopped to support the currency symbols in a reliablemanner), US mutual funds, options on US stocks, several precious metals andquite possibly more; see theYahoo!Finance website for fullinformation.Finance::YahooQuote can be used for stocks fromthe USA, Canada, various European exchanges, various Asian exchanges(Singapore, Taiwan, HongKong, Kuala Lumpur, ...) Australia and NewZealand. It should work for other markets supported by Yahoo.You may optionally override the default LWP timeout of 180 secondsby setting$Finance::YahooQuote::TIMEOUT to yourpreferred value.You may also provide a proxy (for the required http connection) byusing the variable$Finance::YahooQuote::PROXY. Furthermore,authentication-based proxies can be used by setting the proxy userand password via the variables$Finance::YahooQuote::PROXYUSER and$Finance::YahooQuote::PROXYPASSWD.Two example scripts are provided to help with the mapping a stocksymbols as well as withYahoo!Finance server codes.
Provided aMy Yahoo! account, goto the followinghttp://edit.my.yahoo.com/config/edit_pfview?.vk=v1. Viewingthe source of this page, you will come across the section thatdefines the menus that let you select which elements go into aparticular view. Theoption values are the strings thatpick up the information described in the menu item. For example,Symbol refers to the strings and name refers to thestringl. Usingsl as the format string, wewould get the symbol followed by the name of the security.
The example scriptexamine_server.sh shows this in some moredetail and downloads example .csv files usingGNU wget.
This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or (atyour option) any later version.
The information that you obtain with this library may be copyrightedby Yahoo! Inc., and is governed by their usage license. See thegeneral disclaimer for more information.
djpadz@padz.net), PadzNet, Inc., wrote theoriginal version. Dirk Eddelbuettel (edd@debian.org) providedseveral extensions.Last modified: Thu Mar 25 22:17:12 CDT 2010