GeniusTrader/Analyzers/GrossGain.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 54 CC 7 SCAR 35.1
CC
7
Cov
0%
calculate
56.0
initialize
2.0
BEGIN
2.0
CRAP 33.5
1 package Finance::GeniusTrader::Analyzers::GrossGain;
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 = ("GrossGain[#*]");
17 @DEFAULT_ARGS = ();
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::Analyzers::GrossGain - The gross gain
22  
23 =head1 DESCRIPTION
24  
25 The gross gain
26  
27 =head2 Parameters
28  
29 none
30  
31 =cut
32  
33 sub initialize {
34 1;
35 }
36  
37 sub calculate {
38 my ($self, $calc, $last, $first, $portfolio) = @_;
39 my $name = $self->get_name;
40  
41 if ( !defined($portfolio) ) {
42 $portfolio = $calc->{'pf'};
43 }
44 if ( !defined($first) ) {
45 $first = $calc->{'first'};
46 }
47 if ( !defined($last) ) {
48 $last = $calc->{'last'};
49 }
50  
51 my @ret = ();
52 foreach my $position (@{$portfolio->{'history'}}) {
53 my $pstats = $position->stats($portfolio);
54 my $diff = $pstats->{'sold'} - $pstats->{'bought'};
55 my $var = 0;
56 if ($position->is_long) {
57 $var = ( $pstats->{'bought'} != 0 ) ?
58 ( $diff / $pstats->{'bought'} ) : 0;
59 } else {
60 $var = ($pstats->{'sold'} !=0 ) ?
61 ( $diff / $pstats->{'sold'} ) : 0;
62 }
63 push @ret, $diff;
64 }
65  
66 $calc->indicators->set($name, $last, \@ret);
67 }
68  
69 1;