GeniusTrader/Analyzers/ProfitFactorGT.pm untested

filter: Statementstmt 0.0% 0 / 30 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 / 48 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::ProfitFactorGT;
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 = ("ProfitFactorGT[#*]");
17 @DEFAULT_ARGS = ("{A:AvgGain}", "{A:AvgLoss}");
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::Analyzers::Profitfactor - Calculates the profitfactor
22  
23 =head1 DESCRIPTION
24  
25 Calculate the Profitfactor by dividing the average of the gains by the
26 average of the losses.
27  
28 =head2 Parameters
29  
30 =over
31  
32 =item Average of the Gains
33  
34 =item Average of the Lossse
35  
36 =back
37  
38 =cut
39  
40 sub initialize {
41 1;
42 }
43  
44 sub calculate {
45 my ($self, $calc, $last, $first, $portfolio) = @_;
46 my $name = $self->get_name;
47  
48 if ( !defined($portfolio) ) {
49 $portfolio = $calc->{'pf'};
50 }
51 if ( !defined($first) ) {
52 $first = $calc->{'first'};
53 }
54 if ( !defined($last) ) {
55 $last = $calc->{'last'};
56 }
57  
58 if ( defined($portfolio) ) {
59 $self->{'portfolio'} = $portfolio;
60 }
61  
62 my $avg_g = $self->{'args'}->get_arg_values($calc, $last, 1);
63 my $avg_l = $self->{'args'}->get_arg_values($calc, $last, 2);
64 my $ret = 0;
65 $ret = $avg_g / ($avg_l * -1) unless ( $avg_l == 0 );
66  
67 $calc->indicators->set($name, $last, $ret);
68 }
69  
70 1;