| 1 | package Math::Business::EMA; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | 1; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub tag { (shift)->{tag} } | ||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub recommended { croak "no recommendation" } | ||||||||||||||||||||||||||
|
Subroutine
recommended: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||
| 14 | 17 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 17 | my $this = bless { | |||||||||||||||||||||||||||
| 16 | EMA => undef, | ||||||||||||||||||||||||||||
| 17 | R => 0, | ||||||||||||||||||||||||||||
| 18 | R1 => 0, | ||||||||||||||||||||||||||||
| 19 | }, $class; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 17 | my $days = shift; | |||||||||||||||||||||||||||
| 22 | 17 | ▶ | if( defined $days ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 2 | $this->set_days( $days ); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 17 | return $this; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub set_days { | ||||||||||||||||||||||||||||
| 30 | 17 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_days: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 17 | my $arg = int(shift); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 17 | ▶ | croak "days must be a positive non-zero integer" if $arg <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 17 | $this->{R} = 2.0 / (1.0 + $arg); | |||||||||||||||||||||||||||
| 36 | 17 | $this->{R1} = (1 - $this->{R}); | |||||||||||||||||||||||||||
| 37 | 17 | $this->{days} = $arg; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 17 | $this->{tag} = "EMA($this->{days})"; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub insert { | ||||||||||||||||||||||||||||
| 43 | 6614 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 6614 | ▶ | croak "You must set the number of days before you try to insert" if not $this->{R}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6614 | ▶ | while( defined(my $Yt = shift) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 6619 | ▶ | if( defined(my $e = $this->{EMA}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 6406 | $this->{EMA} = ( $this->{R} * $Yt ) + ( $this->{R1} * $e ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||
| 52 | 213 | my ($p,$N); | |||||||||||||||||||||||||||
| 53 | 213 | ▶ | if( ref($p = $this->{_p}) and (($N = @$p) >= $this->{days}-1) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref($p = $this->{"_p"}) and ($N = @$p) >= $this->{"days"} - 1
MC/DC100%2/2
ref($p = $this->{"_p"}) and ($N = @$p) >= $this->{"days"} - 1
ref($p = $this->{"_p"})
($N = @$p) >= $this->{"days"} - 1
Truth table100%3/3
A and B
A= ref($p = $this->{"_p"})B= ($N = @$p) >= $this->{"days"} - 1
| |||||||||||||||||||||||||||||
| 54 | 15 | my $sum = 0; | |||||||||||||||||||||||||||
| 55 | 15 | $sum += $_ for @$p; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 15 | $this->{EMA} = ( $this->{R} * $Yt ) + ( $this->{R1} * ($sum/$N) ); | |||||||||||||||||||||||||||
| 58 | 15 | delete $this->{_p}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||
| 61 | 198 | push @{$this->{_p}}, $Yt; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub query { | ||||||||||||||||||||||||||||
| 68 | 6537 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 6537 | return $this->{EMA}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||