Finance::Shares::Averages - Moving average lines and tests
use Finance::Shares::Sample; use Finance::Shares::Averages; my $s = new Finance::Shares::Sample(...); my $id1 = $s->simple_average( graph => 'prices', line => 'close', period => 5, strict => 1, shown => 1, style => {...}, # PostScript::Graph::Style key => 'My Momentum Line', ); my $id2 = $s->weighted_average(...); my $id3 = $s->exponential_average(...);
This package provides additional methods for Finance::Shares::Sample objects. The functions provide moving average lines. Once a line has been constructed it may be referred to by a text identifier returned by the function. The functions may also be referred to by their text names in a model specification (full or short version):
avg simple_average wgt weighted_average exp exponential_average
They all take the same parameters in hash key/value format. All of these keys are optional.
A string indicating the graph for display: one of prices, volumes, cycles or signals. (Default: 'prices')
A string indicating the data/function to be averaged - normally the closing prices. (Default: 'close')
The number of readings used in making up the moving average. The actual time spanned depends on how the sample was configured. (Default: 5)
If 1, return undef if the average period is incomplete. If 0, return the best value so far. (Default: 0)
A flag controlling whether the function is graphed. 0 to not show it, 1 to add the line to the named graph. (Default: 1)
graph
A hash ref holding settings suitable for the PostScript::Graph::Style object used when drawing the line. By default lines and points are plotted, with each line in a slightly different style. (Default: undef)
If given this becomes the visual identifier, shown on the Chart key panel.
Produce a series of values representing a simple moving average over the entire sample period. An arithmetical mean of the previous period values is calculated.
period
Nothing is done if there are no suitable data in the sample. Returns the hash key identifying the line to Finance::Shares::Sample.
Produce a series of values representing a weighted moving average over the entire sample period. This is like a simple moving average except that the most recent values carry more weight.
Produce a series of values representing an exponential moving average over the entire sample period. Unlike a weighted average, all of the previous values are taken into accound. period affects how quickly the weighting falls off.
Please report those you find to the author.
Chris Willmot, chris@willmot.org.uk
Finances::Shares::Sample, Finance::Shares::Chart and Finances::Shares::Model.
There is also an introduction, Finance::Shares::Overview and a tutorial beginning with Finance::Shares::Lesson1.
To install TestFuncs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TestFuncs
CPAN shell
perl -MCPAN -e shell install TestFuncs
For more information on module installation, please visit the detailed CPAN module installation guide.