GeniusTrader/Indicators/Generic/Speed.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 47 CC 4 SCAR 21.5
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 8.5
1 package Finance::GeniusTrader::Indicators::Generic::Speed;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::Indicators;
13 use Finance::GeniusTrader::Prices;
14 use Finance::GeniusTrader::Tools qw(:generic);
15 use Finance::GeniusTrader::Eval;
16  
17 @ISA = qw(Finance::GeniusTrader::Indicators);
18 @NAMES = ("Speed[#*]","PercentSpeed[#*]");
19 @DEFAULT_ARGS = ("{I:Prices CLOSE}");
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::Generic::Speed - Speed of a indicator
24  
25 =head1 DESCRIPTION
26  
27 This function returns today's value minus yesterday's value of the indicator
28 given on arguments. Without indicator, the close price is used.
29  
30 =cut
31  
32 sub initialize {
33 my ($self) = @_;
34  
35 $self->add_arg_dependency(1, 2);
36 }
37  
38 sub calculate {
39 my ($self, $calc, $i) = @_;
40
41 return if ($calc->indicators->is_available($self->get_name(0), $i));
42 return if (! $self->check_dependencies($calc, $i));
43
44 my $today = $self->{'args'}->get_arg_values($calc, $i, 1);
45 my $yesterday = $self->{'args'}->get_arg_values($calc, $i - 1, 1);
46  
47 $calc->indicators->set($self->get_name(0), $i, $today - $yesterday);
48 if ($yesterday)
49 {
50 $calc->indicators->set($self->get_name(1), $i,
51 100 * ($today - $yesterday) / abs($yesterday)
52 );
53 }
54 }