GeniusTrader/Analyzers/Accumulate.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 45 CC 4 SCAR 23.0
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 10.0
1 package Finance::GeniusTrader::Analyzers::Accumulate;
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::Analyzers;
13 use Finance::GeniusTrader::Calculator;
14  
15 @ISA = qw(Finance::GeniusTrader::Analyzers);
16 @NAMES = ("Accumulate[#*]");
17 @DEFAULT_ARGS = ("{A:Costs}");
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::Analyzers::Accumulate - Accumulates the Days of arg1
22  
23 =head1 DESCRIPTION
24  
25 Accumulates the values of the array that is given as arg1.
26  
27 This means if the array consists of the values (1,2,3,4) the result is
28 (1,3,6,10).
29  
30  
31 =head2 Parameters
32  
33 First argument: Array reference to be accumulated
34  
35  
36 =head2 Return
37  
38 Returns an array, not considering first and last parameter.
39  
40 =cut
41  
42 sub initialize {
43 1;
44 }
45  
46 sub calculate {
47 my ($self, $calc, $last, $first, $portfolio) = @_;
48 my $name = $self->get_name;
49  
50 if ( !defined($portfolio) ) {
51 $portfolio = $calc->{'pf'};
52 }
53 if ( !defined($first) ) {
54 $first = $calc->{'first'};
55 }
56 if ( !defined($last) ) {
57 $last = $calc->{'last'};
58 }
59  
60 my $array = $self->{'args'}->get_arg_values($calc, $last, 1);
61  
62 my $sum = 0;
63 my @ret = ();
64 foreach my $f (@{$array}) {
65 $sum += $f;
66 push @ret, $sum;
67 }
68  
69 $calc->indicators->set($name, $last, \@ret );
70 }
71  
72 1;