line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Google::Sector::Mean; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23248
|
use Statistics::Basic qw(:all); |
|
1
|
|
|
|
|
24805
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
41065
|
use List::Util qw(min max); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
129
|
|
5
|
1
|
|
|
1
|
|
11277
|
use HTML::TreeBuilder; |
|
1
|
|
|
|
|
39807
|
|
|
1
|
|
|
|
|
14
|
|
6
|
1
|
|
|
1
|
|
1103
|
use LWP::Simple qw($ua get); |
|
1
|
|
|
|
|
77881
|
|
|
1
|
|
|
|
|
11
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$ua->timeout(15); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
15
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
16
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# This allows declaration use Finance::NASDAQ::Markets ':all'; |
19
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
20
|
|
|
|
|
|
|
# will save memory. |
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
) ] ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT = qw( |
28
|
|
|
|
|
|
|
sectorsummary |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub sectorsummary{ |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
0
|
|
my ($symbol,$source) = @_; |
38
|
0
|
|
|
|
|
|
my @buffer = (); |
39
|
0
|
|
|
|
|
|
my $url = ""; |
40
|
0
|
|
|
|
|
|
$url = "http://www.google.com/finance"; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my @ids = qw/secperf/; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $content = get $url; |
45
|
0
|
0
|
|
|
|
|
return unless defined $content; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $tree = HTML::TreeBuilder->new; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$tree->parse($content); |
52
|
0
|
|
|
|
|
|
my %quote; |
53
|
0
|
|
|
|
|
|
my %out=(); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
@quote{qw/secperf/} = map { _finddiv($tree,$_,'id') } @ids; |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if(defined($quote{secperf})){ |
59
|
|
|
|
|
|
|
# $quote{yfnc_modtitlew2} =~s/(&|-|\"|\'|\,|\.|amp;)//g; |
60
|
|
|
|
|
|
|
# $quote{yfnc_modtitlew2} =~ m/Sector:(.*?)Industry:(.*?)Full/; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$out{SectorChange}{buffer}=[split "% |down / up",$quote{secperf}]; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
pop @{$out{SectorChange}{buffer}}; |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
foreach(@{$out{SectorChange}{buffer}}){ |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my @set = (); |
72
|
0
|
|
|
|
|
|
$_ = trim($_); |
73
|
0
|
0
|
0
|
|
|
|
next if($_ =~/SectorChange/ || $_ eq ''); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
|
if($_ =~/Non*Cyclical/ && $_ =~/\+/){ |
|
|
0
|
0
|
|
|
|
|
76
|
0
|
|
|
|
|
|
@set = split /\+/,$_; |
77
|
0
|
|
|
|
|
|
$set[0] = "ConsNonCyclical"; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$out{sectors}->{pos}->{$set[0]}=sprintf("%3.3f",$set[1]); |
81
|
|
|
|
|
|
|
}elsif($_ =~/Non*Cyclical/ && $_ =~/\-/){ |
82
|
0
|
|
|
|
|
|
@set = split /\-/,$_; |
83
|
0
|
|
|
|
|
|
$set[0] = "ConsNonCyclical"; |
84
|
0
|
|
|
|
|
|
$set[1] = $set[2]; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$out{sectors}->{pos}->{$set[0]}=sprintf("%3.3f",$set[1]); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
}else{ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if($_ =~ /\+/){ |
93
|
0
|
|
|
|
|
|
@set = split /\+/,$_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$out{sectors}->{pos}->{$set[0]}=sprintf("%3.3f",$set[1]); |
96
|
|
|
|
|
|
|
}else{ |
97
|
0
|
|
|
|
|
|
@set = split /-/,$_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
$set[1]=0.00 unless($set[1]); |
102
|
0
|
|
|
|
|
|
$out{sectors}->{neg}->{$set[0]}=sprintf("%3.3f",$set[1]); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$tree = $tree->delete(); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $i = 0; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$out{avgs}->{pos}->{mean} = mean(values %{$out{sectors}->{pos}}); |
|
0
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$out{avgs}->{pos}->{max} = max(values %{$out{sectors}->{pos}}); |
|
0
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$out{avgs}->{pos}->{min} = min(values %{$out{sectors}->{pos}}); |
|
0
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$out{avgs}->{neg}->{mean} = mean(values %{$out{sectors}->{neg}}); |
|
0
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$out{avgs}->{neg}->{max} = max(values %{$out{sectors}->{neg}}); |
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$out{avgs}->{neg}->{min} = min(values %{$out{sectors}->{neg}}); |
|
0
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
foreach my $sec(keys %{$out{sectors}->{pos}}){ |
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if($out{avgs}->{pos}->{mean} <= $out{sectors}->{pos}->{$sec}){ |
128
|
0
|
|
|
|
|
|
$out{sectors}->{overavg}->{$sec} = $out{sectors}->{pos}->{$sec}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return \%out; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub trim |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
0
|
0
|
|
my $string = shift; |
145
|
0
|
0
|
|
|
|
|
$string = "" unless $string; |
146
|
0
|
|
|
|
|
|
$string =~ s/^\s+//; |
147
|
0
|
|
|
|
|
|
$string =~ s/\s+$//; |
148
|
0
|
|
|
|
|
|
$string =~ s/\t//; |
149
|
0
|
|
|
|
|
|
$string =~ s/^\s//; |
150
|
0
|
|
|
|
|
|
return $string; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# for look_down |
155
|
|
|
|
|
|
|
sub _id { |
156
|
0
|
|
|
0
|
|
|
my $id = shift; |
157
|
|
|
|
|
|
|
return sub { |
158
|
0
|
|
|
0
|
|
|
my ($tag) = @_; |
159
|
0
|
0
|
|
|
|
|
if (defined $tag->attr('id')) { |
160
|
0
|
|
|
|
|
|
return $tag->attr('id') eq $id; |
161
|
|
|
|
|
|
|
} else { |
162
|
0
|
|
|
|
|
|
return 0; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
0
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# for look_down |
168
|
|
|
|
|
|
|
sub _class { |
169
|
0
|
|
|
0
|
|
|
my $id = shift; |
170
|
|
|
|
|
|
|
return sub { |
171
|
0
|
|
|
0
|
|
|
my ($tag) = @_; |
172
|
0
|
0
|
|
|
|
|
if (defined $tag->attr('class')) { |
173
|
0
|
|
|
|
|
|
return $tag->attr('class') eq $id; |
174
|
|
|
|
|
|
|
} else { |
175
|
0
|
|
|
|
|
|
return 0; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
0
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub _findGeneric { |
181
|
0
|
|
|
0
|
|
|
my ($tree,$tag,$id) = @_; |
182
|
0
|
|
|
|
|
|
my $elem = $tree->look_down('_tag',$tag, _id($id)); |
183
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem->as_text : undef; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub _findspan { |
187
|
0
|
|
|
0
|
|
|
my ($tree,$id) = @_; |
188
|
0
|
|
|
|
|
|
my $elem = $tree->look_down('_tag', 'span', _id($id)); |
189
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem->as_text : undef; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
sub _findtd { |
192
|
0
|
|
|
0
|
|
|
my ($tree,$id) = @_; |
193
|
0
|
|
|
|
|
|
my $elem = $tree->look_down('_tag', 'td', _class($id)); |
194
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem->as_text : undef; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub _findtable { |
198
|
0
|
|
|
0
|
|
|
my ($tree,$id,$type) = @_; |
199
|
0
|
0
|
|
|
|
|
my $elem = $tree->look_down('_tag', 'table', $type eq 'id'? _id($id) : _class($id)); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem->as_text : undef; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
sub _findResults { |
206
|
0
|
|
|
0
|
|
|
my ($tree,$id,$type) = @_; |
207
|
0
|
0
|
|
|
|
|
my $elem = $tree->look_down('_tag', 'table', $type eq 'id'? _id($id) : _class($id)); |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem : undef; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub _finddiv { |
215
|
0
|
|
|
0
|
|
|
my ($tree,$id,$type) = @_; |
216
|
0
|
0
|
|
|
|
|
my $elem = $tree->look_down('_tag', 'div', $type eq 'id'? _id($id) : _class($id)); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem->as_text : undef; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _findol { |
224
|
0
|
|
|
0
|
|
|
my ($tree,$id,$type) = @_; |
225
|
0
|
0
|
|
|
|
|
my $elem = $tree->look_down('_tag', 'ol', $type eq 'id'? _id($id) : _class($id)); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
0
|
0
|
|
|
|
|
return defined $elem ? $elem->as_text : undef; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# format %quote as a string |
233
|
|
|
|
|
|
|
sub _as_text { |
234
|
0
|
|
|
0
|
|
|
my ($symbol,%quote) = @_; |
235
|
0
|
|
|
|
|
|
return sprintf ("%s: \$%2.2f, %s%s (%s%s), vol %s", $symbol, |
236
|
|
|
|
|
|
|
@quote{qw/prc sgn net sgn pct vol/}); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
1; |
244
|
|
|
|
|
|
|
__DATA__ |