App/Chart/Series/Derived/TMA.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran n/a Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 80 CC 1 SCAR 6.9
CC
1
Cov
0%
longname
2.0
shortname
2.0
manual
2.0
CRAP 2.0
1 # Copyright 2008, 2009, 2010, 2011 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Series::Derived::TMA;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use Locale::TextDomain 1.17; # for __p()
23 use Locale::TextDomain ('App-Chart');
24 use Math::Trig ();
25  
26 use base 'App::Chart::Series::Indicator';
27 use App::Chart::Series::Calculation;
28 use App::Chart::Series::Derived::SMA;
29  
30 use constant DEBUG => 0;
31  
32 # http://www.linnsoft.com/tour/techind/movAvg.htm
33 # Formula, and sample TMA N=20 on Nasdaq 100 (symbol QQQ, yahoo now in
34 # ^IXIC) from 2001.
35 #
36  
37  
38  
39 sub longname { __('TMA - Triangular MA') }
40 sub shortname { __('TMA') }
41 sub manual { __p('manual-node','Triangular Moving Average') }
42  
43 use constant
44 { priority => -10,
45 type => 'average',
46 parameter_info => [ { name => __('Days'),
47 key => 'tma_days',
48 type => 'integer',
49 minimum => 1,
50 default => 20 } ],
51 };
52  
53 sub new {
54 my ($class, $parent, $N) = @_;
55 ### TMA new(): @_
56  
57 $N //= $class->parameter_info->[0]->{'default'};
58 ($N > 0) || croak "TMA bad N: $N";
59  
60 return $class->SUPER::new
61 (parent => $parent,
62 parameters => [ $N ],
63 arrays => { values => [] },
64 array_aliases => { });
65 }
66 *warmup_count = \&App::Chart::Series::Derived::SMA::warmup_count; # $N-1
67  
68 sub proc {
69 my ($self_or_class, $N) = @_;
70 # eg. N=5 gives 1, 2, 3, 2, 1
71 # eg. N=6 gives 1, 2, 3, 3, 2, 1
72 return App::Chart::Series::Calculation::ma_proc_by_weights
73 (1 .. int($N/2), (reverse 1 .. int(($N+1)/2)));
74 }
75  
76 1;
77 __END__