GeniusTrader/Indicators/Cheating/MeanPossiblePerformance.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 4 SCAR 22.2
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 9.2
1 package Finance::GeniusTrader::Indicators::Cheating::MeanPossiblePerformance;
2  
3 # Copyright 2000-2002 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::Indicators;
13 use Finance::GeniusTrader::Prices;
14 use Finance::GeniusTrader::Tools qw(:math);
15  
16 @ISA = qw(Finance::GeniusTrader::Indicators);
17 @NAMES = ("MeanPossiblePerformance[#*]", "MeanPossiblePerformancePercent[#*]");
18 @DEFAULT_ARGS = (20, "{I:Prices CLOSE}");
19  
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::MeanPossiblePerformance
24  
25 =head1 DESCRIPTION
26  
27  
28 =head1 PARAMETERS
29  
30 =over
31  
32 =item Number of days
33  
34 The number of days the indicator looks in the future
35  
36 =item Data
37  
38 This is the data to use as input. If you don't specify anything, the
39 close price will be used by default.
40  
41 =back
42  
43  
44 =cut
45  
46 sub initialize {
47 }
48  
49 sub calculate {
50 my ($self, $calc, $i) = @_;
51 my $name = $self->get_name(0);
52 my $namepercent = $self->get_name(1);
53 my $lastday = $calc->prices->count();
54 my $days = $self->{'args'}->get_arg_values($calc, $i, 1);
55  
56 return if ( $calc->indicators->is_available($name, $i) );
57 return if ($i+$days >= $lastday);
58  
59 my $res = 0;
60 my $buy = $self->{'args'}->get_arg_values($calc, $i, 2);
61 for (my $j=$i+1; $j<=$i+$days; $j++) {
62 my $today = $self->{'args'}->get_arg_values($calc, $j, 2);
63 $res += $today - $buy;
64 }
65 $res = ($days==0) ? 0 : $res / $days;
66  
67 $calc->indicators->set($name, $i, $res);
68 $calc->indicators->set($namepercent, $i, $res*100/$self->{'args'}->get_arg_values($calc, $i, 2));
69  
70 }