blib/lib/Math/Business/MACD.pm

filter: Statementstmt 76.6% 46 / 60 Branchbran 54.5% 12 / 22 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 78.5% 11 / 14 Podpod 0.0% 0 / 10 totaltotal 63.7% 74 / 116 SCAR 29.8
CC
14
Cov
69%
query_histogram
12.0
query
6.6
set_days
4.1
CRAP 19.7
« blib/lib/Math/Business/DMI.pm ↑ Summary blib/lib/Math/Business/RSI.pm »
1 package Math::Business::MACD;
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 ▶use Math::Business::EMA;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 1;
10  
11 0 ▶sub tag { (shift)->{tag} }
Subroutine tag: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 sub recommended {
14 0 ▶ my $class = shift;
Subroutine recommended: not called CC=1 SCAR=6.9
Pod undocumented
15  
16 0 $class->new(26, 12, 9);
17 }
18  
19 sub new {
20 1 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.4
Pod undocumented
21  
22 1 my $this = bless {
23 slow_EMA => new Math::Business::EMA,
24 fast_EMA => new Math::Business::EMA,
25 trig_EMA => new Math::Business::EMA,
26 days => 0,
27 }, $class;
28  
29 1 ▶ if( @_ == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) 0 1 1
30 0 $this->set_days(@_);
31 }
32  
33 1 return $this;
34 }
35  
36 sub set_days {
37 1 ▶ my $this = shift;
Subroutine set_days: called CC=4 SCAR=14.1
Pod undocumented
38 1 my ($slow, $fast, $trig) = @_;
39  
40 1 ▶ croak "slow days must be a positive non-zero integers" if $slow <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $slow <= 0 0 1 1
41 1 ▶ croak "fast days must be a positive non-zero integers" if $fast <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $fast <= 0 0 1 1
42 1 ▶ croak "trig days must be a positive non-zero integers" if $trig <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $trig <= 0 0 1 1
43  
44 1 $this->{days} = 1;
45  
46 1 $this->{slow_EMA}->set_days($slow);
47 1 $this->{fast_EMA}->set_days($fast);
48 1 $this->{trig_EMA}->set_days($trig);
49  
50 1 $this->{tag} = "MACD($fast,$slow,$trig)";
51 }
52  
53 2 ▶sub query_trig_ema { my $this = shift; return $this->{trig_EMA}->query }
Subroutine query_trig_ema: called CC=1 SCAR=0.0
Pod undocumented
54 42 ▶sub query_slow_ema { my $this = shift; return $this->{slow_EMA}->query }
Subroutine query_slow_ema: called CC=1 SCAR=0.0
Pod undocumented
55 42 ▶sub query_fast_ema { my $this = shift; return $this->{fast_EMA}->query }
Subroutine query_fast_ema: called CC=1 SCAR=0.0
Pod undocumented
56  
57 sub query_histogram {
58 0 ▶ my $this = shift;
Subroutine query_histogram: not called CC=3 SCAR=24.8
Pod undocumented
59  
60 0 my $m = $this->query;
61 0 my $t = $this->query_trig_ema;
62  
63 0 ▶ return unless defined($m) and defined($t);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m and defined $t 0 0 0
Condition0%0/3
defined $m and defined $t
!ll&&!rl&&r
000
MC/DC0%0/2
defined $m and defined $t
defined $m defined $t
Truth table0%0/3
A and B
A= defined $mB= defined $t
ABresult
0X0
100
111
64 0 return $m - $t;
65 }
66  
67 sub query {
68 42 ▶ my $this = shift;
Subroutine query: called CC=5 SCAR=18.9
Pod undocumented
69  
70 42 my $f = $this->query_fast_ema;
71 42 my $s = $this->query_slow_ema;
72  
73 42 ▶ return unless defined($f) and defined($s);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and defined $s 26 16 42
Condition100%3/3
defined $f and defined $s
!ll&&!rl&&r
111516
MC/DC100%2/2
defined $f and defined $s
defined $f defined $s
Truth table100%3/3
A and B
A= defined $fB= defined $s
ABresult
0X0
100
111
74 16 ▶ if( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 16 16
75 0 my $m = $f-$s;
76 0 ▶ my $t = $this->query_trig_ema; return unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 0 0
77 0 my $h = $m-$t;
78  
79 0 return ( $m, $f, $s, $t, $h );
80 }
81 16 return $f - $s;
82 }
83  
84 sub insert {
85 39 ▶ my $this = shift;
Subroutine insert: called CC=4 SCAR=13.9
Pod undocumented
86  
87 39 ▶ croak "You must set the number of days before you try to insert" if not $this->{days};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"days"} 0 39 39
88  
89 39 ▶ while( defined( my $value = shift ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = shift())) 39 39 78
90 39 $this->{slow_EMA}->insert($value);
91 39 $this->{fast_EMA}->insert($value);
92  
93 39 my $m = $this->query;
94 39 ▶ $this->{trig_EMA}->insert( $m ) if defined($m);
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 14 25 39
95 }
96 }
97  
98 __END__
« blib/lib/Math/Business/DMI.pm ↑ Summary blib/lib/Math/Business/RSI.pm »