blib/lib/Math/Business/BollingerBands.pm

filter: Statementstmt 94.2% 66 / 70 Branchbran 65.0% 13 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 7 totaltotal 78.7% 89 / 113 SCAR 27.5
CC
15
Cov
86%
insert
11.2
query
2.3
set_deviations
2.0
CRAP 15.6
« blib/lib/Math/Business/RSI.pm ↑ Summary blib/lib/Math/Business/CCI.pm »
1 package Math::Business::BollingerBands;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 1;
8  
9 0 ▶sub tag { (shift)->{tag} }
Subroutine tag: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 sub recommended {
12 0 ▶ my $class = shift;
Subroutine recommended: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 0 $class->new(20, 2);
15 }
16  
17 sub new {
18 1 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
19 1 my $this = bless {
20 dev => [],
21 val => [],
22 N => undef, # days in the average
23 K => undef, # deviations
24 }, $class;
25  
26 1 ▶ if( @_ == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 1 0 1
27 1 $this->set_days($_[0]);
28 1 $this->set_deviations($_[1]);
29 }
30  
31 1 return $this;
32 }
33  
34 sub set_deviations {
35 1 ▶ my $this = shift;
Subroutine set_deviations: called CC=2 SCAR=7.0
Pod undocumented
36 1 my $arg = shift;
37  
38 1 ▶ croak "deviations must be a positive non-zero integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 1 1
39 1 $this->{K} = $arg;
40  
41 1 $this->{tag} = "BOLL($this->{K},$this->{N})";
42 }
43  
44 sub set_days {
45 1 ▶ my $this = shift;
Subroutine set_days: called CC=2 SCAR=6.9
Pod undocumented
46 1 my $arg = int shift;
47  
48 1 ▶ croak "days must be a positive non-zero integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 1 1
49 1 $this->{N} = $arg;
50  
51 1 $this->{val} = [];
52 1 $this->{dev} = [];
53  
54 1 delete $this->{M};
55 1 delete $this->{U};
56 1 delete $this->{L};
57  
58 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 $this->{tag} = "BOLL($this->{K},$this->{N})";
60 }
61  
62 sub insert {
63 5 ▶ my $this = shift;
Subroutine insert: called CC=11 SCAR=24.1
Pod undocumented
64 5 my $val = $this->{val};
65  
66 5 my $N = $this->{N};
67 5 my $K = $this->{K};
68  
69 5 ▶ croak "You must set the number of days and deviations before you try to insert" unless $N and $K;
Branch: 1 branch
BranchTrueFalseTotal
unless $N and $K 0 5 5
Condition33%1/3
$N and $K
!ll&&!rl&&r
005
MC/DC0%0/2
$N and $K
$N $K
Truth table33%1/3
A and B
A= $NB= $K
ABresult
0X0
100
111
70 5 ▶ while( defined(my $value = shift) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = shift())) 42 5 47
71 42 push @$val, $value;
72  
73 42 ▶ if( @$val >= $N ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$val >= $N) 23 19 42
74 23 ▶ if( defined( my $s = $this->{M} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $s = $this->{'M'})) { } 22 1 23
75 22 my $old = shift @$val;
76 22 $this->{M} = my $M = $s - $old/$N + $value/$N;
77  
78 22 my @dev = map {($_-$M)**2} @$val;
79  
80 22 my $sum = 0;
81 22 $sum += $_ for @dev;
82 22 $sum /= $N;
83  
84 22 ▶ my $k_stddev = $K * ($sum<0.000_000_000_6 ? 0 : sqrt($sum));
Branch: 1 branch
BranchTrueFalseTotal
$sum < 6e-10 ? : 0 22 22
85 22 $this->{L} = $M - $k_stddev;
86 22 $this->{U} = $M + $k_stddev;
87  
88 } else {
89 1 my $sum = 0;
90 1 $sum += $_ for @$val;
91  
92 1 $this->{M} = my $M = $sum/$N;
93 1 my @dev = map {($_-$M)**2} @$val;
94  
95 1 $sum = 0;
96 1 $sum += $_ for @dev;
97 1 $sum /= $N;
98  
99 1 ▶ my $k_stddev = $K * ($sum<0.000_000_000_6 ? 0 : sqrt($sum));
Branch: 1 branch
BranchTrueFalseTotal
$sum < 6e-10 ? : 0 1 1
100 1 $this->{L} = $M - $k_stddev;
101 1 $this->{U} = $M + $k_stddev;
102 }
103 }
104 }
105 }
106  
107 sub query {
108 4 ▶ my $this = shift;
Subroutine query: called CC=2 SCAR=8.1
Pod undocumented
109  
110 4 ▶ return ($this->{L}, $this->{M}, $this->{U}) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 4 0 4
111 0 return $this->{M};
112 }
113  
114 __END__
« blib/lib/Math/Business/RSI.pm ↑ Summary blib/lib/Math/Business/CCI.pm »