NAME

Finance::Shares::Bands - High and low boundaries

SYNOPSIS

    use Finance::Shares::Sample;
    use Finance::Shares::Bands;

    $s = new Finance::Shares::Sample(...);

    ($high, $low) = $s->envelope(percent => 4);
    ($high, $low) = $s->bollinger_bands();
    ($high, $low) = $s->channel(
	graph  => 'prices',
	line   => 'close',
	period => 20,
	style  => {...},
	shown  => 1,
	key    => '20 day channel',
    );
    

DESCRIPTION

This package provides additional methods for Finance::Shares::Sample objects. The functions provide two boundary lines, above and below another source line. Once the lines have been constructed they may be referred to by text identifiers returned by the function. The functions may also be referred to by their text names in a model specification (short or full version):

env	    envelope
boll    bollinger_band
chan    channel

They mostly take the same parameters, all 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 central data/function. (Default: 'close')

percent

[envelope only]. The lines are generated this percentage above and below the guide line. (Default: 3)

period

[bollinger and channel only]. The number of days, weeks or months being sampled.

If 'strict' is set, this will always be 20 for Bollinger bands. 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.

strict

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

For Bollinger bands this would normally be 1, where the period will be 20 quotes. Setting this to 0 relaxes this rule, allowing period to be set.

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)

If style is a hash ref, a seperate Style is used for each line. To get both lines to have the same appearance, pass a PostScript::Graph::Style reference.

key

If given this becomes the visual identifier, shown on the Chart key panel. The software appends words 'high' or 'low' as appropriate.

envelope

Add lines a given percentage above and below the main data line.

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.

Like all functions, this returns the line identifiers. However, there are two, an upper and a lower bound, so they are returned as a list:

(high_id, low_id)

bollinger_bands

A Bollinger band comprising upper and lower boundary lines is placed around a main data line. The lines are 2 standard deviations above and below the main data line. The band is sensitive to volatility, narrowing if the data is stable and widening as the variance increases.

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 (the default line id). Buy or sell signals may be generated if prices move outside this.

Even without strict, there is always a lead-in period where values are undefined.

Like all functions, this returns the line identifiers. However, there are two, an upper and a lower bound, so they are returned as a list:

(high_id, low_id)

channel

This is the function which will give functions like 52 week highs or the lowest price in the last 30 days. Lines are added above and below the main data line which show the highest and lowest points in the specified period.

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.

Like all functions, this returns the line identifiers. However, there are two, an upper and a lower bound, so they are returned as a list:

(high_id, low_id)

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.