GeniusTrader/Indicators/WMA.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 42 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::WMA;
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 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::Indicators;
13  
14 @ISA = qw(Finance::GeniusTrader::Indicators);
15 @NAMES = ("WMA[#*]");
16 @DEFAULT_ARGS = (20, "{I:Prices CLOSE}");
17  
18 =head1 Finance::GeniusTrader::Indicators::WMA
19  
20 =head2 Overview
21  
22 The Weighted Moving Average (WMA) is designed to put more weight on recent data and less weight on past data. A weighted moving average is calculated by multiplying each of the previous day's data by a weight.
23  
24 =head2 Calculation
25  
26 WMA(5) = (1/15) * (5 * Close(i) + 4 * Close(i - 1) + 3 * Close(i - 2) + 2 * Close(i - 3) + 1 * Close(i - 4))
27  
28 =head2 Examples
29  
30 Finance::GeniusTrader::Indicators::WMA->new()
31 Finance::GeniusTrader::Indicators::WMA->new([50])
32 Finance::GeniusTrader::Indicators::WMA->new([30], "OPEN", $GET_OPEN)
33  
34 =head2 Links
35  
36 http://www.equis.com/free/taaz/movingaverages.html
37  
38 =cut
39  
40 sub initialize {
41 my ($self) = @_;
42 }
43  
44 =head2 Finance::GeniusTrader::Indicators::WMA::calculate($calc, $day)
45  
46 =cut
47 sub calculate {
48 my ($self, $calc, $i) = @_;
49 my $nb = $self->{'args'}->get_arg_values($calc, $i, 1);
50 my $name = $self->get_name;
51 my $weight = 0;
52 my $sum_of_weight = 0;
53 my $sum = 0;
54
55 $self->remove_volatile_dependencies();
56 $self->add_volatile_arg_dependency(2, $nb);
57  
58 return if ($calc->indicators->is_available($name, $i));
59 return if (! $self->check_dependencies($calc, $i));
60  
61 for(my $n = $i - $nb + 1; $n <= $i; $n++)
62 {
63 $weight += 1;
64 $sum += $self->{'args'}->get_arg_values($calc, $n, 2) * $weight;
65 $sum_of_weight += $weight;
66 }
67 $calc->indicators->set($name, $i, $sum / $sum_of_weight);
68 }
69  
70 1;