1YahooQuote(3) User Contributed Perl Documentation YahooQuote(3)
2
3
4
6 Finance::YahooQuote - Get stock quotes from Yahoo! Finance
7
9 use Finance::YahooQuote;
10 # setting TIMEOUT and PROXY is optional
11 $Finance::YahooQuote::TIMEOUT = 60;
12 $Finance::YahooQuote::PROXY = "http://some.where.net:8080";
13 @quote = getonequote $symbol; # Get a quote for a single symbol
14 @quotes = getquote @symbols; # Get quotes for a bunch of symbols
15 useExtendedQueryFormat(); # switch to extended query format
16 useRealtimeQueryFormat(); # switch to real-time query format
17 @quotes = getquote @symbols; # Get quotes for a bunch of symbols
18 @quotes = getcustomquote(["DELL","IBM"], # using custom format
19 ["Name","Book Value"]); # note array refs
20
22 This module gets stock quotes from Yahoo! Finance. The getonequote
23 function will return a quote for a single stock symbol, while the
24 getquote function will return a quote for each of the stock symbols
25 passed to it. getcustomquote allows to specify a format other than the
26 default to take advantage of the extended range of available informa‐
27 tion.
28
29 The download operation is efficient: only one request is made even if
30 several symbols are requested at once. The return value of getonequote
31 is an array, with the following elements:
32
33 0 Symbol
34 1 Company Name
35 2 Last Price
36 3 Last Trade Date
37 4 Last Trade Time
38 5 Change
39 6 Percent Change
40 7 Volume
41 8 Average Daily Vol
42 9 Bid
43 10 Ask
44 11 Previous Close
45 12 Today's Open
46 13 Day's Range
47 14 52-Week Range
48 15 Earnings per Share
49 16 P/E Ratio
50 17 Dividend Pay Date
51 18 Dividend per Share
52 19 Dividend Yield
53 20 Market Capitalization
54 21 Stock Exchange
55
56 If the extended format has been selected, the following fields are also
57 retrieved:
58
59 22 Short ratio
60 23 1yr Target Price
61 24 EPS Est. Current Yr
62 25 EPS Est. Next Year
63 26 EPS Est. Next Quarter
64 27 Price/EPS Est. Current Yr
65 28 Price/EPS Est. Next Yr
66 29 PEG Ratio
67 30 Book Value
68 31 Price/Book
69 32 Price/Sales
70 33 EBITDA
71 34 50-day Moving Avg
72 35 200-day Moving Avg
73
74 If the real-time format has been selected, the following fields are
75 also retrieved:
76
77 36 Ask (real-time)
78 37 Bid (real-time)
79 38 Change in Percent (real-time)
80 39 Last trade with time (real-time)
81 40 Change (real-time)
82 41 Day range (real-time)
83 42 Market-cap (real-time)
84
85 The getquote function returns an array of pointers to arrays with the
86 above structure.
87
88 The getonequote function returns just one quote, rather than an array.
89 It returns a simple array of values for the given symbol.
90
91 The setQueryString permits to supply a new query string that will be
92 used for subsequent data requests.
93
94 The useExtendedQueryFormat and useRealtimeQueryFormat are simpler
95 interfaces which append symbols to the default quote string, as
96 detailed above.
97
98 The getcustomquote returns an array of quotes corresponding to values
99 for the symbols supplied in the first array reference, and the custom
100 fields supplied in the second array reference. Here the custom fields
101 correspond to the 'named' fields of the list below.
102
103 Beyond stock quotes, Finance::YahooQuote can also obtain quotes for
104 currencies (from the Philadephia exchange -- however Yahoo! appears to
105 have stopped to support the currency symbols in a reliable manner), US
106 mutual funds, options on US stocks, several precious metals and quite
107 possibly more; see the Yahoo! Finance website for full information.
108 Finance::YahooQuote can be used for stocks from the USA, Canada, vari‐
109 ous European exchanges, various Asian exchanges (Singapore, Taiwan,
110 HongKong, Kuala Lumpur, ...) Australia and New Zealand. It should work
111 for other markets supported by Yahoo.
112
113 You may optionally override the default LWP timeout of 180 seconds by
114 setting $Finance::YahooQuote::TIMEOUT to your preferred value.
115
116 You may also provide a proxy (for the required http connection) by
117 using the variable $Finance::YahooQuote::PROXY. Furthermore, authenti‐
118 cation-based proxies can be used by setting the proxy user and password
119 via the variables $Finance::YahooQuote::PROXYUSER and
120 $Finance::YahooQuote::PROXYPASSWD.
121
122 Two example scripts are provided to help with the mapping a stock sym‐
123 bols as well as with Yahoo! Finance server codes. The regression tests
124 scripts in the t/ subdirectory of the source distribution also contain
125 simple examples.
126
127 The available custom fields
128
129 The following list contains all the available data fields at Yahoo!
130 along with the corresponding format string entry:
131
132 Symbol s
133 Name n
134 Last Trade (With Time) l
135 Last Trade (Price Only) l1
136 Last Trade Date d1
137 Last Trade Time t1
138 Last Trade Size k3
139 Change and Percent Change c
140 Change c1
141 Change in Percent p2
142 Ticker Trend t7
143 Volume v
144 Average Daily Volume a2
145 More Info i
146 Trade Links t6
147 Bid b
148 Bid Size b6
149 Ask a
150 Ask Size a5
151 Previous Close p
152 Open o
153 Day's Range m
154 52-week Range w
155 Change From 52-wk Low j5
156 Pct Chg From 52-wk Low j6
157 Change From 52-wk High k4
158 Pct Chg From 52-wk High k5
159 Earnings/Share e
160 P/E Ratio r
161 Short Ratio s7
162 Dividend Pay Date r1
163 Ex-Dividend Date q
164 Dividend/Share d
165 Dividend Yield y
166 Float Shares f6
167 Market Capitalization j1
168 1yr Target Price t8
169 EPS Est. Current Yr e7
170 EPS Est. Next Year e8
171 EPS Est. Next Quarter e9
172 Price/EPS Est. Current Yr r6
173 Price/EPS Est. Next Yr r7
174 PEG Ratio r5
175 Book Value b4
176 Price/Book p6
177 Price/Sales p5
178 EBITDA j4
179 50-day Moving Avg m3
180 Change From 50-day Moving Avg m7
181 Pct Chg From 50-day Moving Avg m8
182 200-day Moving Avg m4
183 Change From 200-day Moving Avg m5
184 Pct Chg From 200-day Moving Avg m6
185 Shares Owned s1
186 Price Paid p1
187 Commission c3
188 Holdings Value v1
189 Day's Value Change w1,
190 Holdings Gain Percent g1
191 Holdings Gain g4
192 Trade Date d2
193 Annualized Gain g3
194 High Limit l2
195 Low Limit l3
196 Notes n4
197 Last Trade (Real-time) with Time k1
198 Bid (Real-time) b3
199 Ask (Real-time) b2
200 Change Percent (Real-time) k2
201 Change (Real-time) c6
202 Holdings Value (Real-time) v7
203 Day's Value Change (Real-time) w4
204 Holdings Gain Pct (Real-time) g5
205 Holdings Gain (Real-time) g6
206 Day's Range (Real-time) m2
207 Market Cap (Real-time) j3
208 P/E (Real-time) r2
209 After Hours Change (Real-time) c8
210 Order Book (Real-time) i5
211 Stock Exchange x
212
214 How can one figure out the format string?
215
216 Provided a My Yahoo! (http://my.yahoo.com) account, go to the following
217 URL:
218
219 http://edit.my.yahoo.com/config/edit_pfview?.vk=v1
220
221 Viewing the source of this page, you will come across the section that
222 defines the menus that let you select which elements go into a particu‐
223 lar view. The <option> values are the strings that pick up the infor‐
224 mation described in the menu item. For example, Symbol refers to the
225 string "s" and name refers to the string "l". Using "sl" as the format
226 string, we would get the symbol followed by the name of the security.
227
228 The example script examine_server.sh shows this in some more detail and
229 downloads example .csv files using GNU wget.
230
231 What about different stock symbols for the same corporation?
232
233 This can be issue. For the first few years, Yahoo! Finance's servers
234 appeared to be cover their respective local markets. E.g., the UK-based
235 servers provided quotes for Europe, the Australian one for the Aus‐
236 tralia and New Zealand and so on. Hence, one needed to branch and
237 bound code and map symbols to their region's servers.
238
239 It now appears that this is no longer required, which is good news as
240 it simplifies coding. However, some old symbols are no longer supported
241 -- yet other, and supported, codes exist for the same company. For
242 example, German stocks used to quoted in terms or their cusip-like
243 'WKN'. The main server does not support these, but does support newer,
244 acronym-based symbols. The example script examine_server.sh helps in
245 finding the mapping as e.g. from 555750.F to DTEGN.F for Deutsche
246 Telekom.
247
249 Copyright 1998, 1999, 2000, 2001, 2002 Dj Padzensky Copyright 2002,
250 2003 Dirk Eddelbuettel
251
252 This program is free software; you can redistribute it and/or modify it
253 under the terms of the GNU General Public License as published by the
254 Free Software Foundation; either version 2 of the License, or (at your
255 option) any later version.
256
257 The information that you obtain with this library may be copyrighted by
258 Yahoo! Inc., and is governed by their usage license. See
259 http://www.yahoo.com/docs/info/gen_disclaimer.html for more informa‐
260 tion.
261
263 Dj Padzensky ("djpadz@padz.net"), PadzNet, Inc., wrote the original
264 version. Dirk Eddelbuettel ("edd@debian.org") provided several exten‐
265 sions based on DJ's original work and is the current maintainer.
266
268 The Finance::YahooQuote home pages are found at
269 http://www.padz.net/~djpadz/YahooQuote/ and http://dirk.eddelbuet‐
270 tel.com/code/yahooquote.html.
271
272 The smtm (Show Me The Money) program uses Finance::YahooQuote for a
273 customisable stock/portfolio ticker and chart display, see
274 http://dirk.eddelbuettel.com/code/smtm.html for more. The beancounter
275 program uses it to store quotes in a SQL database, see
276 http://dirk.eddelbuettel.com/code/beancounter.html.
277
278
279
280perl v5.8.8 2005-07-17 YahooQuote(3)