NAME

Finance::QuoteHist::Yahoo - Site-specific subclass for retrieving historical stock quotes.

SYNOPSIS

use Finance::QuoteHist::Yahoo;
$q = new Finance::QuoteHist::Yahoo
   (
    symbols    => [qw(IBM UPS AMZN)],
    start_date => '01/01/1999',
    end_date   => 'today',      
   );

# Adjusted values
foreach $row ($q->quotes()) {
  ($symbol, $date, $open, $high, $low, $close, $volume) = @$row;
  ...
}

# Non adjusted values
$q->adjusted(0);
foreach $row ($q->quotes()) {
   ($symbol, $date, $open, $high, $low, $close, $volume, $adj_close) = @$row;
}

# Splits
foreach $row ($q->splits()) {
   ($symbol, $date, $post, $pre) = @$row;
}

# Dividends
foreach $row ($q->dividends()) {
   ($symbol, $date, $dividend) = @$row;
}

DESCRIPTION

Finance::QuoteHist::Yahoo is a subclass of Finance::QuoteHist::Generic, specifically tailored to read historical quotes, dividends, and splits from the Yahoo web site (http://charts.yahoo.com/).

For quotes and dividends, Yahoo can return data quickly in CSV format. For quotes, non-adjusted values are available in HTML. Splits are only found embedded in the non-adjusted HTML produced for quotes. Behind the scenes, an HTML quote query is performed when splits are requested; quotes are retained based on the first successful query type. Unless told otherwise, via the adjusted() method, the non-adjusted quotes will be automatically adjusted by applying the ratio derived from the adjusted closing value and non-adjusted closing value. This does not apply if quotes were retrieved using CSV.

There are no date range restrictions on CSV queries for quotes and dividends.

For HTML queries, Yahoo takes arbitrary date ranges as arguments, but breaks results into pages of 200 entries.

The quote_urls() and dividend_urls methods provide all the URLs necessary given the target, date range, and symbols, whether they be for HTML or CSV data. These are automatically utilized by the native methods of Finance::QuoteHist::Generic.

Please see Finance::QuoteHist::Generic(3) for more details on usage and available methods. If you just want to get historical quotes and are not interested in the details of how it is done, check out Finance::QuoteHist(3).

METHODS

The basic user interface consists of four methods, as seen in the example above. Those methods are:

quotes()

Returns a list of rows (or a reference to an array containing those rows, if in scalar context). Each row contains the Date, Open, High, Low, Close, and Volume for that date. Optionally, if non-adjusted values were requested, their will be an extra element at the end of the row for the Adjusted closing price.

dividends()

Returns a list of rows (or a reference to an array containing those rows, if in scalar context). Each row contains the Date and amount of the Dividend, in that order.

splits()

Returns a list of rows (or a reference to an array containing those rows, if in scalar context). Each row contains the Date, Post split shares, and Pre split shares, in that order.

adjusted($boolean)

Sets whether adjusted or non-adjusted quotes are desired. Quotes are pre-adjusted by default.

There are some extra methods and overridden methods in the Yahoo class that deserve a little explanation for developers interested in developing a similar site-specific module:

source_type($type)

Sets or returns the desired type of output from Yahoo. Valid settings are 'csv' and 'html'. By default this is 'csv', where possible, but will sometimes be set to 'html' in cases where there is no choice, such as when split information is requested. In these cases, the desired source type is temporarily saved for the duration of the query and restored afterwards.

The following methods override methods provided by the Finance::QuoteHist::Generic module; more of this was necessary than is typical for a basic query site due to the variety of query types and data formats available on Yahoo.

quote_urls()
dividend_urls()

Provides the URLs necessary for direct quote and dividend queries; depending on the value returned by the source_type() method, these URLs are either for HTML or CSV data.

dividend_extract()
split_extract()

The presence of these filters will lift dividend and split information from the regular HTML quote output of Yahoo. In the case of splits, this is the only way to get the information, hence there is no split_urls() method present.

split_get()

The mere presence of the split_extract() method would normally be enough for extraction retrieval. In this case, however, the data must be in HTML format. By overriding the method, 'html' can be specifically (and temporarily) requested for the duration of the query since the split information is not present in the CSV formats.

csv_parser()

Unfortunate hack. Yahoo just happens to return CSV data from direct dividend queries in a mangled format (the CSV separator is different for the header row vs. the rest of the rows). This corrects that before passing it along to the regular csv_parser() method.

REQUIRES

Finance::QuoteHist::Generic

DISCLAIMER

The data returned from these modules is in no way guaranteed, nor are the developers responsible in any way for how this data (or lack thereof) is used. The interface is based on URLs and page layouts that might change at any time. Even though these modules are designed to be adaptive under these circumstances, they will at some point probably be unable to retrieve data unless fixed or provided with new parameters. Furthermore, the data from these web sites is usually not even guaranteed by the web sites themselves, and oftentimes is acquired elsewhere.

In the case of Yahoo, as of September 13, 2000, their statement reads, in part:

Historical chart data and daily updates provided by
Commodity Systems, Inc. (CSI). Data and information is 
provided for informational purposes only, and is not
intended for trading purposes. Neither Yahoo nor any of
its data or content providers (such as CSI) shall be
liable for any errors or delays in the content, or for
any actions taken in reliance thereon.

If you would like to know more, check out where this statement was found:

http://chart.yahoo.com/d

Better yet, you might want to read their disclaimer page:

http://www.yahoo.com/info/misc/disclaimer.html

If you still have concerns, then use another site-specific historical quote instance, or none at all.

Above all, play nice.

AUTHOR

Matthew P. Sisk, <sisk@mojotoad.com>

COPYRIGHT

Copyright (c) 2000 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Finance::QuoteHist::Generic(3), Finance::QuoteHist(3), perl(1).