GeniusTrader/Analyzers/AvgCosts.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::AvgCosts;
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 # DELETE MARK
10  
11 use strict;
12 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
13  
14 use Finance::GeniusTrader::Analyzers;
15 use Finance::GeniusTrader::Calculator;
16  
17 @ISA = qw(Finance::GeniusTrader::Analyzers);
18 @NAMES = ("AvgCosts[#*]");
19 @DEFAULT_ARGS = ();
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Analyzers::AvgCosts - Average Costs per trade
24  
25 =head1 DESCRIPTION
26  
27 The mean costs of the portfolio
28  
29 =cut
30  
31 sub initialize {
32 1;
33 }
34  
35 sub calculate {
36 my ($self, $calc, $last, $first, $portfolio) = @_;
37 my $name = $self->get_name;
38  
39 if ( !defined($portfolio) ) {
40 $portfolio = $calc->{'pf'};
41 }
42 if ( !defined($first) ) {
43 $first = $calc->{'first'};
44 }
45 if ( !defined($last) ) {
46 $last = $calc->{'last'};
47 }
48  
49 if ( defined($portfolio) ) {
50 $self->{'portfolio'} = $portfolio;
51 }
52  
53 my $sum = 0;
54 my $anz = 0;
55 foreach my $position (@{$self->{'portfolio'}->{'history'}})
56 {
57 my $pstats = $position->stats($self->{'portfolio'});
58 $sum += $pstats->{'cost'};
59 $anz++;
60 }
61 $sum = $sum / $anz if ($anz != 0);
62  
63 $calc->indicators->set($name, $last, $sum);
64 }
65  
66 1;