NAME

Finance::Shares::Averages - Moving average lines and tests

SYNOPSIS

    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(...);
    

DESCRIPTION

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.

graph

A string indicating the graph for display: one of prices, volumes, cycles or signals. (Default: 'prices')

line

A string indicating the data/function to be averaged - normally the closing prices. (Default: 'close')

period

The number of readings used in making up the moving average. The actual time spanned depends on how the sample was configured. (Default: 5)

strict

If 1, return undef if the average period is incomplete. If 0, return the best value so far. (Default: 0)

shown

A flag controlling whether the function is graphed. 0 to not show it, 1 to add the line to the named graph. (Default: 1)

style

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)

key

If given this becomes the visual identifier, shown on the Chart key panel.

simple_average

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.

Nothing is done if there are no suitable data in the sample. Returns the hash key identifying the line to Finance::Shares::Sample.

weighted_average

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.

Nothing is done if there are no suitable data in the sample. Returns the hash key identifying the line to Finance::Shares::Sample.

exponential_average

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.

Nothing is done if there are no suitable data in the sample. Returns the hash key identifying the line to Finance::Shares::Sample.

BUGS

Please report those you find to the author.

AUTHOR

Chris Willmot, chris@willmot.org.uk

SEE ALSO

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.