GeniusTrader/Indicators/Generic/Sum.pm untested

filter: Statementstmt 0.0% 0 / 39 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 / 55 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::Sum;
2  
3 # Copyright 2003 Oliver Bossert
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(:math);
15 use Finance::GeniusTrader::ArgsTree;
16  
17 @ISA = qw(Finance::GeniusTrader::Indicators);
18 @NAMES = ("Sum[#*]");
19 @DEFAULT_ARGS = (14, "{I:Prices CLOSE}");
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::Generic::Sum - Calculation of the Sum of the last n days
24  
25 =head1 DESCRIPTION
26  
27 Calculates the Sum of the last n days.
28  
29 =head2 Overview
30  
31 =head2 Calculation
32  
33 =head2 Examples
34  
35 Finance::GeniusTrader::Indicators::Generic::SumUp->new()
36  
37 =head2 Links
38  
39 =cut
40  
41 sub initialize {
42 my ($self) = @_;
43 }
44  
45 sub calculate {
46 my ($self, $calc, $i) = @_;
47 my $nb = $self->{'args'}->get_arg_values($calc, $i, 1);
48 my $name = $self->get_name;
49 my $sum = 0;
50 my $today;
51  
52 return if (! defined($nb));
53  
54 $self->remove_volatile_dependencies();
55 $self->add_volatile_arg_dependency(2, $nb);
56  
57 return if ($calc->indicators->is_available($name, $i));
58 return if (! $self->check_dependencies($calc, $i));
59  
60 for(my $n = $i - $nb + 1; $n <= $i; $n++)
61 {
62 $today = $self->{'args'}->get_arg_values($calc, $n, 2);
63 $sum += $today;
64 }
65 $calc->indicators->set($name, $i, $sum);
66 }
67  
68 1;