line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::CMA;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
82846
|
use 5.010000;
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
33
|
use warnings;
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
90
|
|
6
|
2
|
|
|
2
|
|
10
|
use List::Util qw/min max sum/;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1048
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter;
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
13
|
|
|
|
|
|
|
central_moving_averages
|
14
|
|
|
|
|
|
|
) ] );
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT = qw(
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
);
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.1';
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub central_moving_averages {
|
25
|
101
|
|
|
101
|
0
|
275357
|
my $smoothing = shift;
|
26
|
101
|
|
|
|
|
177
|
my @series = @{shift()};
|
|
101
|
|
|
|
|
469
|
|
27
|
101
|
|
|
|
|
469
|
my $count = min($smoothing, $#series);
|
28
|
101
|
|
|
|
|
144
|
my $left = -$count;
|
29
|
101
|
|
|
|
|
116
|
my $right = $count;
|
30
|
101
|
|
|
|
|
116
|
my $sum = 0;
|
31
|
101
|
|
|
|
|
99
|
my @result;
|
32
|
|
|
|
|
|
|
|
33
|
101
|
50
|
|
|
|
266
|
return @series unless $count > 0;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# sum first element and window to the right
|
36
|
101
|
|
|
|
|
189
|
for (0 .. $count) {
|
37
|
3159
|
|
|
|
|
3519
|
$sum += $series[$_];
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# head
|
41
|
101
|
|
|
|
|
258
|
while ($left < 0) {
|
42
|
3058
|
|
|
|
|
3516
|
push @result, $sum / ($right + 1);
|
43
|
3058
|
|
|
|
|
2570
|
$left++;
|
44
|
3058
|
100
|
|
|
|
7449
|
$sum += $series[++$right] if $right < $#series;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# middle part
|
48
|
101
|
|
|
|
|
102
|
while (1) {
|
49
|
832
|
|
|
|
|
1068
|
push @result, $sum / ($right - $left + 1);
|
50
|
832
|
|
|
|
|
912
|
$sum -= $series[$left++];
|
51
|
832
|
100
|
|
|
|
1469
|
last if $right >= $#series;
|
52
|
731
|
|
|
|
|
835
|
$sum += $series[++$right];
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# tail
|
56
|
101
|
|
|
|
|
246
|
while (@result < @series) {
|
57
|
843
|
|
|
|
|
983
|
push @result, $sum / ($right - $left + 1);
|
58
|
843
|
|
|
|
|
1746
|
$sum -= $series[$left++];
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
101
|
|
|
|
|
1140
|
@result;
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1;
|
65
|
|
|
|
|
|
|
__END__
|