File Coverage

blib/lib/LBMA/Statistics.pm
Criterion Covered Total %
statement 22 52 42.3
branch 0 12 0.0
condition n/a
subroutine 7 10 70.0
pod 4 4 100.0
total 33 78 42.3


line stmt bran cond sub pod time code
1             package LBMA::Statistics;
2              
3 7     7   180263 use warnings;
  7         23  
  7         233  
4 7     7   40 use strict;
  7         17  
  7         358  
5              
6             our $VERSION = '0.061';
7              
8 7     7   4148 use LBMA::Statistics::Date;
  7         19  
  7         230  
9 7     7   5128 use LBMA::Statistics::GoldFixing::Daily;
  7         25  
  7         265  
10 7     7   5177 use LBMA::Statistics::SilverFixing::Daily;
  7         20  
  7         237  
11 7     7   48 use Log::Log4perl qw/:easy/;
  7         14  
  7         51  
12              
13             =head1 NAME
14              
15             LBMA::Statistics - Obtain Gold and Silver Fixings (Prices) from London Bullion Market
16              
17             =head1 DESCRIPTION
18              
19             This module obtains Gold and Silver Fixings (Prices) from Statistics of the London Bullion Market L and the underlying table L.
20              
21             Information returned by this module is governed by LBMA's terms and conditions.
22              
23             C
24             to incorporate them into commercial products which you intend to market, sell or otherwise
25             provide to third parties, you must pay the required fee and obtain a licence from
26             The London Gold Market Fixing Limited and / or The London Silver Market Fixing Limited as appropriate.
27             See www.goldfixing.com and www.silverfixing.com for full details.>
28              
29             It's designed to use with cron to retrieve data on a B basis in the evening.
30              
31              
32             =head2 London Gold Fixing
33              
34             From Wikipedia (L):
35              
36             I
37              
38             Gold prices are fixed in United States dollars (USD), Pound sterling (GBP) and since 1999 European euros (EUR).
39              
40             Historic daily prices are available back to 1968.
41              
42              
43             =head2 London Silver Fixing
44              
45              
46             Silver prices are fixed in United States dollars (USD), Pound sterling (GBP) and since 1999 European euros (EUR).
47              
48             Published once a day at 12:00 GMT.
49              
50             Historic daily prices are available back to 1968.
51              
52             =head1 SYNOPSIS
53              
54             =head2 new - Constructor
55              
56             use strict;
57              
58             use warnings;
59              
60             use LBMA::Statistics;
61              
62             my $lbma = LBMA::Statistics->new() or die $!;
63              
64             =cut
65              
66             sub new {
67 2     2 1 28 my $class = shift;
68 2         5 my $self = {};
69 2         8 bless $self, $class;
70 2         9 return $self;
71             }
72              
73             =head2 dailygoldfixing
74              
75             =head3 Parameters
76              
77             Parameters are all lowercase.
78              
79             =over 4
80              
81             =item * year - four digit year (1968 .. )
82              
83             =item * month - one or two digit month (1 .. 12)
84              
85             =item * day - one or two digit day (1 .. 31)
86              
87             =back
88              
89             my @fixings = $lbma->dailygoldfixing(
90             year => $year,
91             month => $month,
92             day => $day,
93             ) or die;
94              
95             If no parameters are passed to this method, today is assumed.
96              
97             Today is determined using UTC. In doubt pass a valid date.
98              
99             my @fixings = $lbma->dailygoldfixing( );
100              
101             Dies if supplied date ain't valid or before 1968.
102              
103              
104             =head3 return values
105              
106             Returns an array of fixings.
107              
108             The number and order of elements varies depending on the year data is retrieved.
109             There is no EUR before 1999.
110              
111              
112             # @fixings 1999 --
113             # 0 date (DD-MMM-YY)
114             # 1 GOLD A.M. USD
115             # 2 GOLD A.M. GBP
116             # 3 GOLD A.M. EUR
117             # 4 GOLD P.M. USD
118             # 5 GOLD P.M. GBP
119             # 6 GOLD P.M. EUR
120             #
121             # @fixings 1968 -- 1998
122             # 0 date (DD-MMM-YY)
123             # 1 GOLD A.M. USD
124             # 2 GOLD A.M. GBP
125             # 3 GOLD P.M. USD
126             # 4 GOLD P.M. GBP
127              
128             In scalar context a reference to an array is returned.
129              
130             Returns undef or empty list if data can't be retrieved e.g. dates without fixing like holidays.
131              
132             Returns an array with the date slot filled and undef for all other slots if you're trying to fetch data before A.M. fixing.
133              
134             Returns an array with the date and A.M. slots filled and whitespace for all other slots if you're trying to fetch data before P.M. and after A.M. fixing.
135              
136              
137             =cut
138              
139             sub dailygoldfixing {
140 0     0 1   my $self = shift;
141 0           my $date = LBMA::Statistics::Date->new(@_);
142 0           my $year = $date->year();
143 0           my $day_pattern = $date->day_pattern();
144 0           my $dailygold = LBMA::Statistics::GoldFixing::Daily->new(
145             year => $year,
146             day_pattern => $day_pattern,
147             );
148 0           my $goldfixing = $dailygold->retrieve_row();
149              
150 0 0         if ( scalar @$goldfixing > 1 ) {
151 0           DEBUG( "Goldfixing Result: ", join( ', ', @$goldfixing ) );
152             }
153             else {
154 0           LOGWARN("No Goldfixing Results: $year, $day_pattern");
155             }
156              
157 0 0         return wantarray ? @$goldfixing : $goldfixing;
158             }
159              
160             =head2 dailygoldfixing_am
161              
162             same as dailygoldfixing but returns just the A.M. Fixing Data
163              
164             my @fixings = $lbma->dailygoldfixing_am( );
165              
166             my @fixings = $lbma->dailygoldfixing_am(
167             year => $year,
168             month => $month,
169             day => $day,
170             ) or die;
171              
172             # @fixings 1999 - ...
173             # 0 date
174             # 1 GOLD A.M. USD
175             # 2 GOLD A.M. GBP
176             # 3 GOLD A.M. EUR
177             # @fixings 1968 - 1998
178             # 0 date
179             # 1 GOLD A.M. USD
180             # 2 GOLD A.M. GBP
181              
182             =cut
183              
184             sub dailygoldfixing_am {
185 0     0 1   my $self = shift;
186 0           my $date = LBMA::Statistics::Date->new(@_);
187 0           my $year = $date->year();
188 0           my $day_pattern = $date->day_pattern();
189 0           my $dailygold = LBMA::Statistics::GoldFixing::Daily->new(
190             year => $year,
191             day_pattern => $day_pattern,
192             );
193 0           my $goldfixing = $dailygold->retrieve_row_am();
194              
195 0 0         if ( scalar @$goldfixing > 1 ) {
196 0           DEBUG( "Goldfixing AM Result: ", join( ', ', @$goldfixing ) );
197             }
198             else {
199 0           LOGWARN("No Goldfixing AM Results: $year, $day_pattern");
200             }
201              
202 0 0         return wantarray ? @$goldfixing : $goldfixing;
203             }
204              
205             =head2 dailysilverfixing
206              
207             =head3 Parameters
208              
209             Parameters are all lowercase.
210              
211             =over 4
212              
213             =item * year - four digit year (1968 .. )
214              
215             =item * month - one or two digit month (1 .. 12)
216              
217             =item * day - one or two digit day (1 .. 31)
218              
219             =back
220              
221             my @fixings = $lbma->dailysilverfixing(
222             year => $year,
223             month => $month,
224             day => $day,
225             ) or die;
226              
227             If no parameters are passed to this class, today is assumed.
228             Today is determined using UTC. In doubt pass a valid date.
229              
230             my @fixings = $lbma->dailysilverfixing( );
231              
232             Dies if supplied date ain't valid or before 1968.
233              
234              
235             =head3 return values
236              
237             Returns an array of fixings
238             The number and order of elements varies depending on the year data is retrieved.
239             There is no EUR before 1999.
240              
241             # @fixings 1999 --
242             # 0 date
243             # 1 SILVER USD
244             # 2 SILVER GBP
245             # 3 SILVER EUR
246             #
247             # @fixings 1968 -- 1998
248             # 0 date
249             # 1 SILVER USD
250             # 2 SILVER GBP
251              
252             In scalar context a reference to an array is returned.
253              
254             Returns undef or empty list if data can't be retrieved e.g. dates without fixing like holidays.
255              
256             Returns an array(ref) with the date slot filled and undef for all other slots if you're trying to fetch data before the fixing.
257              
258              
259             =cut
260              
261             sub dailysilverfixing {
262 0     0 1   my $self = shift;
263 0           my $date = LBMA::Statistics::Date->new(@_);
264 0           my $year = $date->year();
265 0           my $day_pattern = $date->day_pattern();
266 0           my $dailysilver = LBMA::Statistics::SilverFixing::Daily->new(
267             year => $year,
268             day_pattern => $day_pattern,
269             );
270 0           my $silverfixing = $dailysilver->retrieve_row();
271 0 0         if ( scalar @$silverfixing > 1 ) {
272 0           DEBUG( "Silverfixing Result: ", join( ', ', @$silverfixing ) );
273             }
274             else {
275 0           LOGWARN("No Silverfixing Results: $year, $day_pattern");
276             }
277 0 0         return wantarray ? @$silverfixing : $silverfixing;
278             }
279              
280             =head1 EXAMPLES
281              
282             =head2 Example 1 Daily Gold Fixing
283              
284             #!/usr/bin/perl
285             use warnings;
286             use strict;
287              
288             use LBMA::Statistics;
289              
290             use Log::Log4perl qw/:easy/;
291              
292             Log::Log4perl->easy_init();
293              
294             my $lbma = LBMA::Statistics->new();
295              
296             print join("|",$lbma->dailygoldfixing() ) ,"\n";
297             print join("|",$lbma->dailygoldfixing( year => 2009, month => 2, day => 2) ) , "\n";
298             print join("|",$lbma->dailygoldfixing( year => 2000, month => 1, day => 4) ) , "\n";
299              
300              
301             =head2 Example 2 Daily Goldy Fixing A.M. data
302              
303             #!/usr/bin/perl
304             use warnings;
305             use strict;
306              
307             use LBMA::Statistics;
308              
309             use Log::Log4perl qw/:easy/;
310              
311             Log::Log4perl->easy_init();
312              
313             my $lbma = LBMA::Statistics->new();
314              
315             # @fixings
316             # 0 date
317             # 1 GOLD A.M. USD
318             # 2 GOLD A.M. GBP
319             # 3 GOLD A.M. EUR
320             print join("|",$lbma->dailygoldfixing_am() ) ,"\n";
321             print join("|",$lbma->dailygoldfixing_am( year => 2009, month => 2, day => 2) ) , "\n";
322             print join("|",$lbma->dailygoldfixing_am( year => 2000, month => 1, day => 4) ) , "\n";
323              
324              
325             =head2 Example 3 Daily Silver Fixing
326              
327             #!/usr/bin/perl
328             use warnings;
329             use strict;
330              
331             use LBMA::Statistics;
332              
333             use Log::Log4perl qw/:easy/;
334              
335             Log::Log4perl->easy_init();
336              
337             my $lbma = LBMA::Statistics->new();
338              
339             print join("|",$lbma->dailysilverfixing() ) ,"\n";
340             print join("|",$lbma->dailysilverfixing( year => 2009, month => 2, day => 2) ) , "\n";
341             print join("|",$lbma->dailysilverfixing( year => 2000, month => 1, day => 4) ) , "\n";
342              
343              
344             =head1 SEE ALSO
345              
346             =over 4
347              
348             =item * Statistics of the London Bullion Market L
349              
350             =item * LBMA Statistics Gold Fixing L
351              
352             =item * LBMA Statistics Silver Fixing L
353              
354             =item * Finance::Quote::GoldMoney L
355              
356             =back
357              
358             =head1 PREREQUISITES
359              
360             =over 4
361              
362             =item * DateTime L
363              
364             =item * WWW::Mechanize L
365              
366             =item * HTML::TableExtract L
367              
368             =item * Log::Log4perl L
369              
370             =back
371              
372             =head1 TODO
373              
374              
375             =over 4
376              
377             =item * Write more tests
378              
379             =item * Find a solution for handling years before 1999 (the years before the european EUR)
380              
381             =item * Add methods to return hashes for data rows
382              
383              
384             =back
385              
386              
387             =head1 AUTHOR
388              
389             Thomas Fahle, C<< >>
390              
391             =head1 BUGS
392              
393             Please report any bugs or feature requests to C, or through
394             the web interface at L. I will be notified, and then you'll
395             automatically be notified of progress on your bug as I make changes.
396              
397              
398             =head1 SUPPORT
399              
400             You can find documentation for this module with the perldoc command.
401              
402             perldoc LBMA::Statistics
403              
404              
405             You can also look for information at:
406              
407             =over 4
408              
409             =item * RT: CPAN's request tracker
410              
411             L
412              
413             =item * AnnoCPAN: Annotated CPAN documentation
414              
415             L
416              
417             =item * CPAN Ratings
418              
419             L
420              
421             =item * Search CPAN
422              
423             L
424              
425             =back
426              
427              
428             =head1 COPYRIGHT & LICENSE
429              
430             Copyright 2009, 2010, 2012, 2014 Thomas Fahle
431              
432             This program is free software; you can redistribute it and/or modify it
433             under the same terms as Perl itself.
434              
435              
436             =cut
437              
438             1; # End of LBMA::Statistics