The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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.

They all take parameters in hash key/value format.

envelope

Add lines pc percent above and below the main data line. All of the following 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

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

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

shown

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

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. All of the following 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')

period

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

strict

Normally 1, where the period will be 20 quotes. Setting this to 0 relaxes this rule, allowing period to be set. (Default: 1)

shown

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

A Bollinger band is bounded by lines 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. All of the following 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')

period

The number of days, weeks or months over which the highest and lowest values are recorded. (Default: 10)

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

shown

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

This function adds lines 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.