| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Math::Business::WMA; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
6177
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
58
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
46
|
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
965
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
1; |
|
8
|
|
|
|
|
|
|
|
|
9
|
0
|
|
|
0
|
0
|
0
|
sub tag { (shift)->[-1] } |
|
10
|
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
0
|
0
|
sub recommended { croak "no recommendation" } |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
5
|
|
|
5
|
0
|
230
|
my $class = shift; |
|
15
|
5
|
|
|
|
|
16
|
my $this = bless [], $class; |
|
16
|
|
|
|
|
|
|
|
|
17
|
5
|
|
|
|
|
10
|
my $days = shift; |
|
18
|
5
|
50
|
|
|
|
16
|
if( defined $days ) { |
|
19
|
5
|
|
|
|
|
15
|
$this->set_days( $days ); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
38
|
return $this; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub set_days { |
|
26
|
5
|
|
|
5
|
0
|
9
|
my $this = shift; |
|
27
|
5
|
|
|
|
|
8
|
my $arg = int(shift); |
|
28
|
|
|
|
|
|
|
|
|
29
|
5
|
50
|
|
|
|
16
|
croak "days must be a positive non-zero even integer" if $arg <= 0; |
|
30
|
5
|
|
|
|
|
27
|
@$this = ( |
|
31
|
|
|
|
|
|
|
$arg, |
|
32
|
|
|
|
|
|
|
($arg*($arg+1))/2, |
|
33
|
|
|
|
|
|
|
[], # the data (we actually need to store it, although we can avoid calculating much of it) |
|
34
|
|
|
|
|
|
|
undef, # the sum of the data |
|
35
|
|
|
|
|
|
|
undef, # the the last numerator |
|
36
|
|
|
|
|
|
|
undef, # the WMA |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
undef, # tag must be last |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
18
|
$this->[-1] = "WMA($arg)"; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub insert { |
|
45
|
4044
|
|
|
4044
|
0
|
392411
|
my $this = shift; |
|
46
|
4044
|
|
|
|
|
7094
|
my ($N, $D, $dat, $total_m, $numerator_m, $EMA) = @$this; |
|
47
|
|
|
|
|
|
|
|
|
48
|
4044
|
50
|
|
|
|
7629
|
croak "You must set the number of days before you try to insert" if not defined $N; |
|
49
|
|
|
|
|
|
|
|
|
50
|
4044
|
|
|
|
|
12200
|
my $old; |
|
51
|
4044
|
|
|
|
|
8517
|
while( defined( my $P = shift ) ) { |
|
52
|
4044
|
|
|
|
|
5706
|
push @$dat, $P; |
|
53
|
|
|
|
|
|
|
|
|
54
|
4044
|
100
|
|
|
|
11758
|
if( @$dat > $N ) { |
|
|
|
100
|
|
|
|
|
|
|
55
|
4002
|
|
|
|
|
5062
|
$old = shift @$dat; |
|
56
|
|
|
|
|
|
|
|
|
57
|
4002
|
|
|
|
|
5964
|
$numerator_m = $numerator_m + $P*$N - $total_m; |
|
58
|
4002
|
|
|
|
|
10787
|
$total_m = $total_m + $P - $old; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} elsif( @$dat == $N ) { |
|
61
|
5
|
|
|
|
|
7
|
$old = 1; |
|
62
|
5
|
|
|
|
|
9
|
my $x = 1; |
|
63
|
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
8
|
$total_m = $numerator_m = 0; |
|
65
|
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
11
|
$numerator_m += $_ for map {$_*$x++} @$dat; |
|
|
42
|
|
|
|
|
80
|
|
|
67
|
5
|
|
|
|
|
33
|
$total_m += $_ for @$dat; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
4044
|
100
|
|
|
|
23870
|
@$this = ($N, $D, $dat, $total_m, $numerator_m, (defined($old) ? $numerator_m/$D:undef)); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub query { |
|
75
|
4044
|
|
|
4044
|
0
|
11433
|
my $this = shift; |
|
76
|
|
|
|
|
|
|
|
|
77
|
4044
|
|
|
|
|
9448
|
return $this->[5]; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |