GeniusTrader/Analyzers/Avg.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 6 SCAR 31.7
CC
6
Cov
0%
calculate
42.0
initialize
2.0
BEGIN
2.0
CRAP 23.8
1 package Finance::GeniusTrader::Analyzers::Avg;
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 = ("Avg[#*]");
17 @DEFAULT_ARGS = ("{A:Costs}");
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::Analyzers::Avg - Calculates the Average of arg1
22  
23 =head1 DESCRIPTION
24  
25 Calculates the Average of arg1
26  
27  
28 =head2 Parameters
29  
30 First argument: Array reference to be averaged
31  
32  
33 =head2 Return
34  
35 Returns an array, not considering first and last parameter.
36  
37 =cut
38  
39 sub initialize {
40 1;
41 }
42  
43 sub calculate {
44 my ($self, $calc, $last, $first, $portfolio) = @_;
45 my $name = $self->get_name;
46  
47 if ( !defined($portfolio) ) {
48 $portfolio = $calc->{'pf'};
49 }
50 if ( !defined($first) ) {
51 $first = $calc->{'first'};
52 }
53 if ( !defined($last) ) {
54 $last = $calc->{'last'};
55 }
56  
57 if ( defined($portfolio) ) {
58 $self->{'portfolio'} = $portfolio;
59 }
60  
61 my $array = $self->{'args'}->get_arg_values($calc, $last, 1);
62  
63 my $sum = 0;
64 my $anz = 0;
65 foreach my $f (@{$array})
66 {
67 $sum += $f;
68 $anz++;
69 }
70 $sum = $sum / $anz if ($anz != 0);
71  
72 $calc->indicators->set($name, $last, $sum);
73 }
74  
75 1;