line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::EMA; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
67797
|
use 5.008003; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
130
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @attributes; |
10
|
|
|
|
|
|
|
BEGIN { |
11
|
|
|
|
|
|
|
# define attributes and implement accessor methods |
12
|
1
|
|
|
1
|
|
3
|
@attributes=qw/alpha ema/; |
13
|
1
|
|
|
|
|
6
|
for( my $i=0; $i<@attributes; $i++ ) { |
14
|
2
|
|
|
|
|
2
|
my $method_num=$i; |
15
|
|
|
|
|
|
|
## no critic |
16
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
82
|
|
17
|
2
|
|
|
308
|
|
345
|
*{__PACKAGE__.'::'.$attributes[$method_num]}= |
|
308
|
|
|
|
|
2355
|
|
18
|
2
|
|
|
|
|
7
|
sub : lvalue {$_[0]->[$method_num]}; |
19
|
|
|
|
|
|
|
## use critic |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
1
|
|
33
|
1
|
1
|
23
|
my $class=ref($_[0]) || $_[0]; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
4
|
my $I=bless []=>$class; |
27
|
1
|
|
|
|
|
5
|
$I->alpha=exp(log(0.001)/10); |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
4
|
for( my $i=1; $i<@_; $i+=2 ) { |
30
|
0
|
|
|
|
|
0
|
$I->{$_[$i]}=$_[$i+1]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
4
|
return $I; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub set_param { |
37
|
1
|
|
|
1
|
1
|
832
|
my ($I, $count, $weight)=@_; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
23
|
$I->alpha=exp(log($weight)/$count); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add { |
43
|
61
|
|
|
61
|
0
|
150
|
my ($I, $value)=@_; |
44
|
|
|
|
|
|
|
|
45
|
61
|
100
|
|
|
|
96
|
$I->ema=defined($I->ema) ? (1-$I->alpha)*$value + $I->alpha*$I->ema : $value; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |