GeniusTrader/Indicators/PERF.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 52 CC 4 SCAR 23.0
CC
4
Cov
0%
calculate
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 10.0
1 package Finance::GeniusTrader::Indicators::PERF;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
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 use strict;
8 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
9  
10 use Finance::GeniusTrader::Indicators;
11 use Finance::GeniusTrader::Tools;
12 use Finance::GeniusTrader::Prices;
13  
14 @ISA = qw(Finance::GeniusTrader::Indicators);
15 @NAMES = ("PERF[#1,#2]");
16 @DEFAULT_ARGS = (0, "{I:Prices CLOSE}");
17  
18 =head1 Finance::GeniusTrader::Indicators::PERF
19  
20 The performance indicator display a security's price performance from
21 a reference day as a percentage. If the market is not available for
22 the reference day, use nearest preceding day.
23  
24 Note: The day must be given in GT internal format and must match the timeframe.
25  
26 Example :
27 Finance::GeniusTrader::Indicators::PERF->new(["2001-09-22"]);
28 Finance::GeniusTrader::Indicators::PERF->new(["2001-09-22", "{I:Prices VOLUME}"]);
29  
30 =head2 Finance::GeniusTrader::Indicators::PERF::calculate($calc, $day)
31  
32 =cut
33  
34 sub calculate {
35 my ($self, $calc, $i) = @_;
36 my $indic = $calc->indicators;
37 my $prices = $calc->prices;
38  
39 my $reference = $self->{'reference'};
40 unless ( defined $reference ) {
41  
42 my $date = $self->{'args'}->get_arg_constant(1);
43 if ( $date ) {
44 $date = $prices->find_nearest_preceding_date($date);
45 $reference = $prices->date($date);
46 } else {
47 $reference = $i;
48 $date = $prices->at($i)->[$DATE];
49 my $name = $self->{'names'}->[0];
50 $name =~ s/PERF\[0,/PERF[$date,/o;
51 $self->{'names'}->[0] = $name;
52 }
53  
54 $self->{'reference'} = $reference;
55  
56 }
57  
58 my $performance_name = $self->get_name(0);
59
60 return if ($indic->is_available($performance_name, $i));
61
62 # Calculate the performance of a security from a reference day in percentage
63 my $performance = ((($self->{'args'}->get_arg_values($calc, $i, 2) - $self->{'args'}->get_arg_values($calc, $reference, 2)) / $self->{'args'}->get_arg_values($calc, $reference, 2)) * 100);
64
65 $indic->set($performance_name, $i, $performance);
66 }
67  
68 1;