NAME

Finance::Shares::mark - A line under user program control

SYNOPSIS

Two examples of how to specify a mark line, one showing the minimum required and the other illustrating all the possible fields.

    use Finance::Shares::Model;
    use Finance::Shares::mark;

    my @spec = (
	...
	lines => [
	    minimal => {
		function => 'mark',
	    },
	    full = {
		function   => 'mark',
		graph      => 'Stock Prices',
		gtype      => 'price',
		first_only => 1,
		key        => 'these are special',
		style      => { ... },
		shown      => 1,
		order      => 99,
	    },
	],
	
	tests => [
	    t1 => q( mark($full, 300) ),
	],
	
	samples => [
	    ...
	    one => {
		test => 't1',
		...
	    }
	],
    );

    my $fsm = new Finance::Shares::Model( @spec );
    $fsm->build();

DESCRIPTION

This module allows model test code to write points or lines on the graphs.

first_only, style and size are the most significant options. Note that there is no line field as the position is set directly in the program function call.

Call Syntax

This module should not be called in the usual way.

There must be a Finance::Shares::Model specification lines entry that has a function field declaring the module's name. However, the entry's tag may only be used in a test code fragment.

mark( $line_tag, $position );

$line_tag is the lines entry tag with a '$' in front. $position is either another line tag or a scalar variable holding a Y axis value. Note that it cannot be an expression.

Example

    lines => [
	low10 = {
	    function => 'lowest',
	    period   => 10,
	    key      => '10 day low',
	}
	test_line => {
	    function => 'mark',
	},
    ],

    test => q(
	mark( $test_line, $low10 - 5 );
    ),

OPTIONS

function

Required. Must be mark.

first_only

Setting this to 1 ensures that only the first mark of this block is shown, rather than a mark for every date that passes the test. A value of 0 means all appropriate values are marked.

This module is only ever invoked from a code fragment within a model test. See "Marking the Chart" in Finance::Shares::test. Typically the code fragment will test the data with some condition such as the following.

mark($mymark, $close) if $line1 > $line2;

Here the mark module code is only visited for those dates where the value of $line1 is above $line2. Typically these would be entries in the model lines specification, which would include:

    lines => [
	line1 => {
	    ...
	},
	line2 => {
	    ...
	},
	mymark => {
	    function => 'mark',
	    ...
	},
    ],

Imagine a sample with the following data.

date	    line1   line2   comp
2003-07-08	    47	    49	    
2003-07-09	    51	    50	    >
2003-07-10	    55	    51	    >
2003-07-11	    53	    52	    >
2003-07-14	    49	    52
2003-07-15	    48	    51
2003-07-16	    51	    50	    >
2003-07-17	    56	    51	    >

With first_only set to 0, there would be five marks. But if first_only was 1, there would be only two - on 2003-07-09 and 2003-07-16.

    [Undefined values can confuse this feature. To be on the safe side either only use data selected by quotes or be sure to let mark() see the undefined dates:

        mark($mymark, $close) if ($line1 > $line2)
    	or (not defined $line1) 
    	or (not defined $line2);

    mark() assumes that dates missed are failures, and will normally show a 'first' marker after a gap. But the gap might be just undefined data and not a series of dates that failed. mark() adjusts for any undefined values it sees, but cannot make allowances for undefined values if it is never called for them.]

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)

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.

There are three special settings, identified by strings circle, up_arrow and down_arrow. They are all affected by the size option. For example,

style => 'up_arrow',
size  => 12,

is equivalent to:

    style => {
	bgnd_outline => 0,
	point => {
	    shape    => 'up_arrow',
	    size     => 12,
	    width    => 2,
	    y_offset => -12,
	},
    },

    

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 276:

Expected text after =item, not a number