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

filter: Statementstmt 0.0% 0 / 55 Branchbran n/a Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 91 CC 1 SCAR 6.9
CC
1
Cov
0%
longname
2.0
shortname
2.0
manual
2.0
CRAP 2.0
1 # Copyright 2007, 2009, 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::Kirshenbaum;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use List::Util qw(min max);
23 use Locale::TextDomain ('App-Chart');
24  
25 use base 'App::Chart::Series::Indicator';
26 use App::Chart::Series::Derived::Bollinger;
27 use App::Chart::Series::Derived::EMA;
28 use App::Chart::Series::Derived::LinRegStderr;
29  
30  
31 sub longname { __('Kirshenbaum Bands') }
32 sub shortname { __('Kirshenbaum') }
33 sub manual { __p('manual-node','Kirshenbaum Bands') }
34  
35 use constant
36 { type => 'average',
37 parameter_info => [ { name => __('Days'),
38 key => 'kirshenbaum_days',
39 type => 'integer',
40 minimum => 1,
41 default => 20 },
42 { name => __('Stderrs'),
43 key => 'kirshenbaum_stderrs',
44 type => 'float',
45 default => 1.75,
46 decimals => 2,
47 step => 0.25,
48 minimum => 0 }],
49 line_colours => { upper => App::Chart::BAND_COLOUR(),
50 lower => App::Chart::BAND_COLOUR() },
51 };
52  
53 sub new {
54 my ($class, $parent, $N, $stderr_factor) = @_;
55  
56 $N //= parameter_info()->[0]->{'default'};
57 ($N > 0) || croak "Kirshenbaum bad N: $N";
58  
59 $stderr_factor //= parameter_info()->[1]->{'default'};
60  
61 return $class->SUPER::new
62 (parent => $parent,
63 parameters => [ $N, $stderr_factor ],
64 arrays => { middle => [],
65 upper => [],
66 lower => [] },
67 array_aliases => { values => 'middle' });
68 }
69  
70 sub proc {
71 my ($class_or_self, $N, $stderr_factor) = @_;
72 my $ema_proc = App::Chart::Series::Derived::EMA->proc($N);
73 my $stderr_proc = App::Chart::Series::Derived::LinRegStderr->proc($N);
74  
75 return sub {
76 my ($value) = @_;
77 my $ema = $ema_proc->($value);
78 my $stderr = $stderr_proc->($value) * $stderr_factor;
79 return ($ema, $ema + $stderr, $ema - $stderr);
80 };
81 }
82 sub warmup_count {
83 my ($self_or_class, $N, $stderr_factor) = @_;
84 return max (App::Chart::Series::Derived::EMA->warmup_count($N),
85 App::Chart::Series::Derived::LinRegStderr->warmup_count($N));
86 }
87 *fill_part = \&App::Chart::Series::Derived::Bollinger::fill_part;
88  
89 1;
90 __END__