Financ...Generic(3pm)
Finance::QuoteHist::Generic(3pm) β User Contributed Perl Documentation
β¨ NAME β¨
Finance::QuoteHist::Generic β the base class for retrieving historical stock quotes. She's the blueprint, bestie. π
π¦ SYNOPSIS π¦
okay so if you're building your own site-specific subclass, the starter pack looks exactly like this:
package Finance::QuoteHist::MyFavoriteSite;
use strict;
use vars qw(@ISA);
use Finance::QuoteHist::Generic;
@ISA = qw(Finance::QuoteHist::Generic);
sub url_maker {
# This method returns a code reference for a routine that, upon
# repeated invocation, will provide however many URLs are necessary
# to fully obtain the historical data for a given target mode and
# parsing mode.
}
πΈ DESCRIPTION πΈ
This is the base class for retrieving historical stock quotes. It's built around LWP::UserAgent. Page results are currently parsed as either CSV or HTML tables.
To actually retrieve historical stock quotes, you have to subclass this class and tailor it to a particular web site. Especially, the url_maker() factory method should be overridden. It provides a code reference to a routine that provides however many URLs are necessary to retrieve the data over a list of symbols within the given date range, for a particular target (quotes, dividends, splits). Different sites have different formats and different limitations on how many quotes are returned for each query. See Finance::QuoteHist::Yahoo for an example of how to do this.
For more complicated sites, such as Yahoo, overriding additional methods might be necessary for dealing with things such as splits and dividends.
π METHODS π
new() πΌ
Returns a new Finance::QuoteHist::Generic object. Valid attributes are:
start_date,end_dateβ Specify the date range from which you would like historical quotes. These dates get parsed by theParseDate()method inDate::Manip, so seeDate::Manip(3)for more information on valid date strings. They are quite flexible, and include such strings as'1 year ago'. Date boundaries can also be dynamically set with methods of the same name. The absence of a start date means go to the beginning of the history. The absence of an end date means go up to the most recent historical date. The absence of both means grab everything.symbolsβ Indicates which ticker symbols to include in the search for historical quotes. Passed either as a string (for single ticker) or an array ref for multiple tickers.granularityβ Returns rows at'daily','weekly', or'monthly'levels of granularity. Defaults to'daily'.attemptsβ Sets how persistently the module tries to retrieve the quotes. There are two places this will manifest. First, if there are what appear to be network errors, this many network connections are attempted for that URL. Secondly, for quotes only, if pages were successfully retrieved, but they contained no quotes, this number of attempts are made to retrieve a document with data. Sometimes sites will report a temporary internal error via HTML, and if it is truly transitory this will usually get around it. The default is3.lineupβ Passed as an array reference (or scalar for single class), this list indicates whichFinance::QuoteHist::Genericsub classes should be invoked in the event this class fails in its attempt to retrieve historical quotes. In the event of failure, the first class in this list is invoked with the same parameters as the original class, and the remaining classes are passed as the lineup to the new class. This sets up a daisy chain of redundancy in the event a particular site is hosed. SeeFinance::QuoteHist(3)to see an example of how this is done in a top level invocation of these modules. This list is empty by default.quote_precisionβ Sets the number of decimal places to which quote values are rounded. This might be of particular significance if there is auto-adjustment taking place (which is only under particular circumstances currently...seeFinance::QuoteHist::Yahoo). Setting this to0will disable the rounding behavior, returning the quote values as they appear on the sites (assuming no auto-adjustment has taken place). The default is4.row_filterβ When provided a subroutine reference, the routine is invoked with an array reference for each raw row retrieved from the quote source. This allows user-defined filtering or formatting for the items of each row. This routine is invoked before any built-in routines are called on the row. The array must be modified directly rather than returned as a value. Use sparingly since the built-in filtering and normalizing routines do expect each row to more or less look like historical stock data. Rearranging the order of the columns in each row is contraindicated.env_proxyβ When set, instructs the underlyingLWP::UserAgentto load proxy configuration information from environment variables. See theua()method andLWP::UserAgentfor more information.auto_proxyβ Same asenv_proxy, but tests first to see if$ENV{http_proxy}is present.verboseβ When set, many status messages are printed toSTDERRindicating progression through URLs and lineup invocations.quietβ When set, certain failure messages are suppressed from appearing onSTDERR. These messages would normally appear regardless the setting of theverboseflag.
The following methods are the primary user interface methods; methods of interest to developers wishing to make their own site-specific instance of this module will find information on overriding methods further below.
quotes() π
Retrieves historical quotes for all provided symbols over the specified date range. Depending on context, returns either a list of rows or an array reference to the same list of rows.
dividends() / splits() πΈ
If available, retrieves dividend or split information for all provided symbols over the specified date range. If there are no site-specific subclassed modules in the lineup capable of getting dividends or splits, the user will be notified on STDERR unless the quiet flag was requested during object creation.
start_date(date_string) / end_date(date_string) ποΈ
Set the date boundaries of all queries. The date_string is interpreted by the Date::Manip module. The absence of a start date means retrieve back to the beginning of that ticker's history. The absence of an end date means retrieve up to the latest date in the history.
clear_cache() π§Ή
When results are gathered for a particular date range, whether they be via direct query or incidental extraction, they are cached. This cache is cleared by invoking this method directly, by resetting the boundary dates of the query, or by changing the adjusted() setting.
quote_source(ticker_symbol) / dividend_source(ticker_symbol) / split_source(ticker_symbol) π
After query, these methods can be used to find out which particular subclass in the lineup fulfilled the corresponding request for a particular ticker symbol.
The following methods are the primary methods of interest for developers wishing to make a site-specific subclass. The url_maker() factory is typically all that is necessary.
url_maker() π
Returns a subroutine reference that serves as an iterrator β yes, that's the spelling in the original, no cap β for producing URLs based on target and parse mode. Repeated calls to this routine produce subsequent URLs in the sequence.
extractors() π§²
For a particular target mode and parse mode, returns a hash containing code references to extraction routines for the remaining targets. For example, for target 'quote' in parse mode 'html' there might be extractor routines for both 'dividend' and 'split'.
ua() π
Accessor method for the LWP::UserAgent object used to process HTTP::Request for individual URLs. This can be handy for such things as configuring proxy access for the underlying user agent. Example:
# Manual configuration
$qh1->ua->proxy(['http'], 'http://proxy.sn.no:8001/');
# Load from environment variables
$qh2->ua->env_proxy();
See LWP::UserAgent for more information on the capabilities of that module.
The following are potentially useful for calling within methods overridden above:
parse_mode($parse_mode) π§©
Set the current parsing mode. Currently parsers are available for html and csv.
target_mode($target_mode) π―
Return the current target mode.
dates($start_date, $end_date) π
Returns a list of business days between and including the provided boundary dates. If no arguments are provided, start_date and end_date default to the currently specified date range.
labels(%parms) π·οΈ
Used to override the default labels for a given target mode and parse mode. Takes the following named parameters:
target_modeβ Can currently be'quote','dividend', or'split'. Default is'quote'.parse modeβ Can currently be'csv'or'html'. The default is typically'csv'but might vary depending on the quote source.labelsβ The following are the default labels. Text entries convert to case- insensitive regular expressions):
target_mode
-------------------------------------------------------
quote => ['date','open','high','low','close',qr(vol|shares)i]
dividend => ['date','div']
split => ['date','post','pre']
β οΈ 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. See the documentation for each site-specific module for more information regarding the disclaimer for that site.
Above all, play nice.
π AUTHOR π
Matthew P. Sisk, <sisk@mojotoad.com>
π COPYRIGHT π
okay bestie, legal moment, stay with me β¨
Copyright (c) 2000-2021 Matthew P. Sisk. All rights reserved. All wrongs revenged. π iconic line, we love a chaotic disclaimer.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. so like, go forth, remix, share, slay π«Άπ
π SEE ALSO π
the friend group, the group chat, the extended universe π
Finance::QuoteHist(3)β the main character this page lives inside of πHTML::TableExtract(3)β how the tables get extracted, iykykDate::Manip(3)β dates, manipulated, no dramaperlmodlib(1)β the module library loreperl(1)β the origin story, the blueprint, the blueprint's blueprint β
and that's a wrap on this page, bestie πβ¨ this beauty came from the perl v5.32.1 docs, dated 2021-03-12 β go read the real thing if you want the full manpage experience, we're just here to make it cute ππ¦
π¦ where this page comes from
- debian bookworm: libfinance-quotehist-perl 1.32-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libfinance-quotehist-perl 1.32-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libfinance-quotehist-perl 1.32-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libfinance-quotehist-perl 1.32-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfinance-quotehist-perl 1.32-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfinance-quotehist-perl 1.32-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms