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 $days = 4;
$s->simple_average(1, 1, 'price', $days);
$s->weighted_average(1, 1, 'price', $days);
$s->exponential_average(1, 1, 'price', $days);
$s->envelope(1,1,'price','weighted',$days,$percent);
$s->bollinger_bands(1,1,'price', 'simple',$days);
$s->channel(1, 1, 'price', 'simple', $days, 20);
DESCRIPTION
Instead of supporting its own class this package provides an extension to Finance::Shares::Sample objects. A number of functions are provided which add moving average or band lines to the Sample's data. These functions may be called directly, but an alternative interface is provided to support Finance::Shares::Model tests. The functions are refered to by a key rather than using function references.
See Finances::Shares::Sample for how to graph the lines, and Finances::Shares::Model for how to use the tests.
simple_average( strict, show, chart, period [, style] )
- strict
-
If 1, return undef if the average period is incomplete. If 0, return the best value so far.
- show
-
A flag controlling whether the function is graphed. 0 to not show it, 1 to add the line to the most suitable panel of the sample's PostScript::Graph::Stock chart.
- chart
-
A string indicating the chart for display: either 'price' or 'volume'.
- period
-
The number of readings used in making up the moving average. The actual time spanned depends on how the sample was configured.
- style
-
An optional 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.
Produce a series of values representing a simple moving average over the entire sample period. Nothing is done if there are no suitable data in the sample.
weighted_average( strict, show, chart, period [, style] )
Produce a series of weighted moving average values from the price data. See simple_average.
exponential_average( strict, show, chart, period [, style] )
Produce a series of expo moving average values from the price data. See simple_average.
envelope( strict, show, chart, func, period, percent [, style] )
- strict
-
Whether 'func' is to be interpreted strictly. See "simple_average".
- show
-
A flag controlling whether the function is graphed. 0 to not show it, 1 to add the line to the most suitable panel of the sample's PostScript::Graph::Stock chart.
- chart
-
A string indicating the chart for display: 'price', 'analysis' or 'volume'.
- func
-
The function identifier used when creating the line, e.g. 'simple', 'weighted' or 'expo'.
- period
-
A string holding additional identifying parameters, e.g. the period for moving averages.
- percent
-
The lines are generated this percentage above and below the guide line.
- style
-
An optional 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.
This function can be used on any data set that can be registered with a Finance::Shares::Model, not just moving averages. It adds lines pc
percent above and below the main data line. This central line is created if it hasn't been generated already, but is not drawn on the chart. So to see all three lines, the main line must be drawn first.
The main reason for generating an envelope around a line is to identify a range of readings that are acceptable. Buy or sell signals may be generated if prices move outside this band.
bollinger_bands( strict, show, chart, func, period, param, [, style] )
- strict
-
Whether 'func' is to be interpreted strictly. See "simple_average".
- show
-
A flag controlling whether the function is graphed. 0 to not show it, 1 to add the line to the most suitable panel of the sample's PostScript::Graph::Stock chart.
- chart
-
A string indicating the chart for display: 'price', 'analysis' or 'volume'.
- func
-
The function identifier used when creating the line, e.g. 'simple', 'weighted' or 'expo'.
- period
-
A string holding additional identifying parameters, e.g. the period for moving averages.
- param
-
The number of days, weeks or months being sampled. If 'strict' is set, this will always be 20. It controls the length of the sample used to calculate the 2 standard deviation above and below, so making it too small will give spurious results.
- style
-
An optional 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.
This function can be used on any data set that can be registered with a Finance::Shares::Model, not just moving averages. It adds lines 2 standard deviations above and below the main data line. This central line is created if it hasn't been generated already, but is not drawn on the chart. So to see all three lines, the main line must be drawn first.
Bollinger bands are always calculated on 20 days, weeks or months. This provides a good sample to reliably measure around 95% of the closing prices. Buy or sell signals may be generated if prices move outside this.
channel( strict, show, chart, func, period, param [, style] )
- strict
-
Whether 'func' is to be interpreted strictly. See "simple_average".
- show
-
A flag controlling whether the function is graphed. 0 to not show it, 1 to add the line to the most suitable panel of the sample's PostScript::Graph::Stock chart.
- chart
-
A string indicating the chart for display: 'price', 'analysis' or 'volume'.
- func
-
The function identifier used when creating the line, e.g. 'simple', 'weighted' or 'expo'.
- period
-
A string holding additional identifying parameters, e.g. the period for moving averages.
- param
-
Another period, this time controlling the channel lines which maintain the smallest and largest value within this time.
- style
-
An optional 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.
This function can be used on any data set that can be registered with a Finance::Shares::Model, not just moving averages. It adds lines above and below the main data line which show the highest and lowest points in the specified period. This central line is created if it hasn't been generated already, but is not drawn on the chart. So to see all three lines, the main line must be drawn first.
The main reason for generating a channel around a line is to identify a range of readings that are acceptable. Buy or sell signals may be generated if prices move outside this band.
BUGS
Please report those you find to the author.
AUTHOR
Chris Willmot, chris@willmot.co.uk
SEE ALSO
Finance::Shares::Sample, Finance::Shares::Model and PostScript::Graph::Stock.