GeniusTrader/Indicators/GAPO.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 3 SCAR 16.1
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.0
1 package Finance::GeniusTrader::Indicators::GAPO;
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::Indicators::Generic::MinInPeriod;
12 use Finance::GeniusTrader::Indicators::Generic::MaxInPeriod;
13 use Finance::GeniusTrader::Prices;
14  
15 @ISA = qw(Finance::GeniusTrader::Indicators);
16 @NAMES = ("GAPO[#*]");
17 @DEFAULT_ARGS = (5, "{I:Prices LOW}", "{I:Prices HIGH}");
18  
19 =head1 Finance::GeniusTrader::Indicators::GAPO
20  
21 =head2 Overview
22  
23 The Gopalakarishnan Range Index (GAPO) characterizes the price behavior of markets. Although GAPO doesn't generate buy or sell signals, it does help identify the random behavior of price activity. A higher value indicates a more erratic market; a lower value indicates consistent price movement.
24  
25 =head2 Calculation
26  
27 GAPO = (Log(Highest High (n) - Lowest Low (n))) / Log (n)
28  
29 =head2 Parameters
30  
31 The standard GAPO index works with a five-day parameter : n = 5
32  
33 =head2 Example
34  
35 Finance::GeniusTrader::Indicators::GAPO->new()
36 Finance::GeniusTrader::Indicators::GAPO->new([6])
37  
38 =head2 Advice/Idea
39  
40 I think that the best way to use the results of this indicator is to look after the average or the moving average of the results, in order to have smooth data.
41  
42 =cut
43 sub initialize {
44 my $self = shift;
45  
46 $self->{'min'} = Finance::GeniusTrader::Indicators::Generic::MinInPeriod->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]);
47 $self->{'max'} = Finance::GeniusTrader::Indicators::Generic::MaxInPeriod->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(3) ]);
48  
49 $self->add_indicator_dependency($self->{'min'}, 1);
50 $self->add_indicator_dependency($self->{'max'}, 1);
51 $self->add_prices_dependency($self->{'args'}->get_arg_names(1));
52 }
53  
54 =head2 Finance::GeniusTrader::Indicators::GAPO::calculate($calc, $day)
55  
56 =cut
57 sub calculate {
58 my ($self, $calc, $i) = @_;
59 my $indic = $calc->indicators;
60 my $q = $calc->prices;
61 my $period = $self->{'args'}->get_arg_names(1);
62 my $min = $self->{'min'};
63 my $max = $self->{'max'};
64 my $min_name = $min->get_name;
65 my $max_name = $max->get_name;
66 my $gapo_name = $self->get_name(0);
67  
68 return if ($indic->is_available($gapo_name, $i));
69 return if (! $self->check_dependencies($calc, $i));
70
71 # Get MIN and MAX values
72 my $min_value = $indic->get($min_name, $i);
73 my $max_value = $indic->get($max_name, $i);
74  
75 # The price range is equal to the difference between the highest price and the lowest price.
76 my $price_range = $max_value - $min_value;
77
78 # The price range divided by the log of the period of observation results in the index value.
79 my $gapo_value = log($price_range) / log($period);
80
81 # Return the result
82 $indic->set($gapo_name, $i, $gapo_value);
83  
84 }
85  
86 1;