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
27 information.
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,
109 various 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,
118 authentication-based proxies can be used by setting the proxy user and
119 password 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
123 symbols as well as with Yahoo! Finance server codes. The regression
124 tests scripts in the t/ subdirectory of the source distribution also
125 contain simple examples.
126
127 The available custom fields
128 The following list contains all the available data fields at Yahoo!
129 along with the corresponding format string entry:
130
131 Symbol s
132 Name n
133 Last Trade (With Time) l
134 Last Trade (Price Only) l1
135 Last Trade Date d1
136 Last Trade Time t1
137 Last Trade Size k3
138 Change and Percent Change c
139 Change c1
140 Change in Percent p2
141 Ticker Trend t7
142 Volume v
143 Average Daily Volume a2
144 More Info i
145 Trade Links t6
146 Bid b
147 Bid Size b6
148 Ask a
149 Ask Size a5
150 Previous Close p
151 Open o
152 Day's Range m
153 52-week Range w
154 Change From 52-wk Low j5
155 Pct Chg From 52-wk Low j6
156 Change From 52-wk High k4
157 Pct Chg From 52-wk High k5
158 Earnings/Share e
159 P/E Ratio r
160 Short Ratio s7
161 Dividend Pay Date r1
162 Ex-Dividend Date q
163 Dividend/Share d
164 Dividend Yield y
165 Float Shares f6
166 Market Capitalization j1
167 1yr Target Price t8
168 EPS Est. Current Yr e7
169 EPS Est. Next Year e8
170 EPS Est. Next Quarter e9
171 Price/EPS Est. Current Yr r6
172 Price/EPS Est. Next Yr r7
173 PEG Ratio r5
174 Book Value b4
175 Price/Book p6
176 Price/Sales p5
177 EBITDA j4
178 50-day Moving Avg m3
179 Change From 50-day Moving Avg m7
180 Pct Chg From 50-day Moving Avg m8
181 200-day Moving Avg m4
182 Change From 200-day Moving Avg m5
183 Pct Chg From 200-day Moving Avg m6
184 Shares Owned s1
185 Price Paid p1
186 Commission c3
187 Holdings Value v1
188 Day's Value Change w1,
189 Holdings Gain Percent g1
190 Holdings Gain g4
191 Trade Date d2
192 Annualized Gain g3
193 High Limit l2
194 Low Limit l3
195 Notes n4
196 Last Trade (Real-time) with Time k1
197 Bid (Real-time) b3
198 Ask (Real-time) b2
199 Change Percent (Real-time) k2
200 Change (Real-time) c6
201 Holdings Value (Real-time) v7
202 Day's Value Change (Real-time) w4
203 Holdings Gain Pct (Real-time) g5
204 Holdings Gain (Real-time) g6
205 Day's Range (Real-time) m2
206 Market Cap (Real-time) j3
207 P/E (Real-time) r2
208 After Hours Change (Real-time) c8
209 Order Book (Real-time) i5
210 Stock Exchange x
211
213 How can one figure out the format string?
214 Provided a My Yahoo! (http://my.yahoo.com) account, go to the following
215 URL:
216
217 http://edit.my.yahoo.com/config/edit_pfview?.vk=v1
218
219 Viewing the source of this page, you will come across the section that
220 defines the menus that let you select which elements go into a
221 particular view. The <option> values are the strings that pick up the
222 information described in the menu item. For example, Symbol refers to
223 the string "s" and name refers to the string "l". Using "sl" as the
224 format string, we would get the symbol followed by the name of the
225 security.
226
227 The example script examine_server.sh shows this in some more detail and
228 downloads example .csv files using GNU wget.
229
230 What about different stock symbols for the same corporation?
231 This can be issue. For the first few years, Yahoo! Finance's servers
232 appeared to be cover their respective local markets. E.g., the UK-based
233 servers provided quotes for Europe, the Australian one for the
234 Australia and New Zealand and so on. Hence, one needed to branch and
235 bound code and map symbols to their region's servers.
236
237 It now appears that this is no longer required, which is good news as
238 it simplifies coding. However, some old symbols are no longer supported
239 -- yet other, and supported, codes exist for the same company. For
240 example, German stocks used to quoted in terms or their cusip-like
241 'WKN'. The main server does not support these, but does support newer,
242 acronym-based symbols. The example script examine_server.sh helps in
243 finding the mapping as e.g. from 555750.F to DTEGN.F for Deutsche
244 Telekom.
245
247 Copyright 1998 - 2002 Dj Padzensky Copyright 2002 - 2007 Dirk
248 Eddelbuettel
249
250 This program is free software; you can redistribute it and/or modify it
251 under the terms of the GNU General Public License as published by the
252 Free Software Foundation; either version 2 of the License, or (at your
253 option) any later version.
254
255 The information that you obtain with this library may be copyrighted by
256 Yahoo! Inc., and is governed by their usage license. See
257 http://www.yahoo.com/docs/info/gen_disclaimer.html for more
258 information.
259
261 Dj Padzensky ("djpadz@padz.net"), PadzNet, Inc., wrote the original
262 version. Dirk Eddelbuettel ("edd@debian.org") provided several
263 extensions based on DJ's original work and is the current maintainer.
264
266 The Finance::YahooQuote home pages are found at
267 http://www.padz.net/~djpadz/YahooQuote/ and
268 http://dirk.eddelbuettel.com/code/yahooquote.html.
269
270 The smtm (Show Me The Money) program uses Finance::YahooQuote for a
271 customisable stock/portfolio ticker and chart display, see
272 http://dirk.eddelbuettel.com/code/smtm.html for more. The beancounter
273 program uses it to store quotes in a SQL database, see
274 http://dirk.eddelbuettel.com/code/beancounter.html.
275
276
277
278perl v5.12.0 2010-03-27 YahooQuote(3)