NAME
Finance::Shares::gradient - Smoothed rate of change
SYNOPSIS
Two examples of how to specify a gradient line, one showing the minimum required and the other illustrating all the possible fields.
use Finance::Shares::Model;
use Finance::Shares::gradient;
my @spec = (
...
lines => [
...
minimal => {
function => 'gradient',
},
full = {
function => 'gradient',
graph => 'Stock Prices',
gtype => 'price',
line => 'some_line',
period => 10,
strict => 1,
key => '10 day gradient',
style => { ... },
shown => 1,
order => -99,
},
...
],
...
samples => [
...
one => {
lines => ['full', 'minimal'],
...
}
],
);
my $fsm = new Finance::Shares::Model( @spec );
$fsm->build();
DESCRIPTION
Momentum is calulcated as the difference in value between now and N periods in the past. This module calulates an average momentum for those N periods.
Strictly, this should be from -N/2 to +N/2 but then the line is undefined at its most recent edge. As this is rarely useful, the default is to use the more normal -N to 0. Note that the end section is not accurate - it gives an idea but it may be wrong. (So what's new in stock price forecasting?)
When period
is 1, the gradient line is a resonable approximation to the rate of change of the source.
The results are normally displayed on an 'analysis' graph as the changes may be positive or negative values. WARNING: if you specify a graph for the gradient line, it will NOT relate to the Y axis. '0' will probably be around the middle (vertically) of the gradient line, while for the Y axis, '0' may well be below the bottom of the page.
To get the line to appear, there must be an entry within the lines block of a Finance::Shares::Model specification. This hash ref must have a function field with the value gradient
. The entry's tag must then appear in the line
field of a sample.
The other main fields are line and period.
OPTIONS
function
Required. Must be gradient
.
graph
If present, this should be a tag declared as a charts
resource. It identifies a particular graph within a chart page. A gtype is implied. (No default)
gtype
Required, unless graph is given. This specifies the type of graph the function lines should appear on. It should be one of price
, volume
, analysis
or level
. (Default: price
)
line
Identifies the line whose data is to be considered. (Default: 'close')
period
The number of values to use. The actual time will depend on the dates by
field. (Default: 5)
Normally at least this number of dates will have been read in before the first date shown on the chart. However, a small initial gap may be visible if some of that working data was missing. Set the dates before
field to adjust this.
strict
Set this to 1 to get the more accurate, but possibly less useful, spread using -N/2 to +N/2 periods. (Default: 0)
key
Most functions generate suitable (if lengthy) entries. This provides the opportunity to identify the line in the Key panel, next to the style.
order
The entries on the graph are sorted according to this value, which defaults to the order required for calculation. A large integer will bring the line to the front and a negative number will put it behind all the rest.
Examples
- -1
-
The line goes behind the data.
- 0.5
-
In front of the data, but only just.
- 999
-
Probably the top line.
shown
1 for the line to be shown, 0 hides it. (Default: 1)
style
This is normally a hash ref defining the data's appearance. See PostScript::Graph::Style for full details, or "Lines" in Finance::Shares::Model for an example.
BUGS
Please let me know when you suspect something isn't right. A short script working from a CSV file demonstrating the problem would be very helpful.
AUTHOR
Chris Willmot, chris@willmot.org.uk
LICENCE
Copyright (c) 2002-2003 Christopher P Willmot
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy can be found at http://www.gnu.org/copyleft/gpl.html
SEE ALSO
Finance::Shares::Overview provides an introduction to the suite, and fsmodel is the principal script.
Modules involved in processing the model include Finance::Shares::Model, Finance::Shares::MySQL, Finance::Shares::Chart. Chart and file details may be found in PostScript::File, PostScript::Graph::Paper, PostScript::Graph::Key, PostScript::Graph::Style.
All functions are invoked from their own modules, all with lower-case names such as Finance::Shares::moving_average. The nitty-gritty on how to write each line specification are found there.
The quote data is stored in a Finance::Shares::data object. For information on writing additional line functions see Finance::Share::Function and Finance::Share::Line. Also, Finance::Share::test covers writing your own tests.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 223:
Expected text after =item, not a number