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

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 83 CC 3 SCAR 13.3
CC
3
Cov
0%
proc
12.0
longname
2.0
shortname
2.0
CRAP 3.8
1 # Copyright 2006, 2007, 2009, 2010 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::PVI;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use List::Util qw(min max);
23 use Locale::TextDomain 1.17; # for __p()
24 use Locale::TextDomain ('App-Chart');
25  
26 use base 'App::Chart::Series::Indicator';
27 use App::Chart::Series::Derived::OBV;
28  
29 sub longname { __('PVI - Positive Volume Index') }
30 sub shortname { __('PVI') }
31 sub manual { __p('manual-node','Negative Volume Index') }
32  
33 use constant
34 { type => 'indicator',
35 units => 'PVI',
36 };
37  
38 sub new {
39 my ($class, $parent) = @_;
40  
41 return $class->SUPER::new
42 (parent => $parent,
43 arrays => { values => [] },
44 array_aliases => { },
45 accumulate => 'multiply');
46 }
47  
48 sub proc {
49 my ($self) = @_;
50 my $parent = $self->parent;
51 my $p = $parent->values_array;
52 my $pv = $parent->array('volumes') || [];
53 sub {
54 my ($i, $value, $prev_i, $prev_value) = @_;
55 if ($prev_value == 0) { return 1; }
56 my $volume = $pv->[$i] // 0;
57 my $prev_volume = $pv->[$prev_i] // 0;
58 if ($volume > $prev_volume) {
59 return $value / $prev_value;
60 } else {
61 return 1;
62 }
63 };
64 }
65  
66 *fill_part = \&App::Chart::Series::Derived::OBV::fill_part;
67  
68 1;
69 __END__