| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | croak "fast days must be a positive non-zero integers" if $fast <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | croak "trig days must be a positive non-zero integers" if $trig <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $m and defined $t
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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $f and defined $s
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
| |||||||||||||||||||||||||||||
| 74 | 16 | ▶ | if( wantarray ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | my $m = $f-$s; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $t = $this->query_trig_ema; return unless defined $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 39 | ▶ | while( defined( my $value = shift ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||