GeniusTrader/Indicators/EPMA.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 48 CC 3 SCAR 18.4
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 6.3
1 package Finance::GeniusTrader::Indicators::EPMA;
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  
12 @ISA = qw(Finance::GeniusTrader::Indicators);
13 @NAMES = ("EPMA[#1,#2]");
14 @DEFAULT_ARGS = (20, "{I:Prices CLOSE}");
15  
16  
17 =head2 Finance::GeniusTrader::Indicators::EPMA
18  
19 =head2 Overview
20  
21 The Endpoint Moving Average (EPMA) is focus on divergences between the original time series and the transposed time series. They may be used in
22 forecasting applications or as additional inputs for neural analyses.
23  
24 =head2 Calculation
25  
26 EPMA(n) = [2 / (n * (n + 1))] * Sum of (((3 * i) - n - 1) * Close(i)) from i = 1 to i = n
27  
28 =head2 Examples
29  
30 Finance::GeniusTrader::Indicators::EPMA->new()
31 Finance::GeniusTrader::Indicators::EPMA->new([50])
32 Finance::GeniusTrader::Indicators::EPMA->new([30], "OPEN", $GET_OPEN)
33  
34 =head2 Links
35  
36 http://www.ivorix.com/en/products/tech/smooth/epma.html
37  
38 =cut
39  
40 sub initialize {
41 my ($self) = @_;
42  
43 $self->add_prices_dependency($self->{'args'}->get_arg_constant(1));
44 }
45 =head2 Finance::GeniusTrader::Indicators::EPMA::calculate($calc, $day)
46  
47 =cut
48 sub calculate {
49 my ($self, $calc, $i) = @_;
50 my $nb = $self->{'args'}->get_arg_constant(1) || 20;
51 my $name = $self->get_name;
52 my $weight = 0;
53 my $sum = 0;
54 my $position = 0;
55
56 return if ($calc->indicators->is_available($name, $i));
57 $self->remove_volatile_dependencies();
58 $self->add_volatile_arg_dependency(2, $nb);
59 return if (! $self->check_dependencies($calc, $i));
60  
61 for(my $n = $i - $nb + 1; $n <= $i; $n++)
62 {
63 $position += 1;
64 $weight = ((3 * $position) - $nb - 1) ;
65 $sum += $self->{'args'}->get_arg_values($calc, $n, 2) * $weight;
66 }
67 my $coef = ( 2 / ($nb * ($nb + 1)));
68 $calc->indicators->set($name, $i, $sum * $coef);
69 }
70  
71 1;