line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::USDX; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27811
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
323
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
our @EXPORT = ('usdx'); |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
89
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
51
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1069
|
use Finance::Quote; |
|
1
|
|
|
|
|
78484
|
|
|
1
|
|
|
|
|
293
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding UTF-8 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Finance::USDX - Compute USDX (US Dollar Index) |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Version 0.02 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Finance::USDX; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# get "live" USDX using YAHOO finance values (through Finance::Quote) |
32
|
|
|
|
|
|
|
my $usdx = usdx(); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# compute USDX given specfic conversion rates |
35
|
|
|
|
|
|
|
my $usdx = usdx(eurusd => 1.2976, usdjpy => 79.846, |
36
|
|
|
|
|
|
|
gbpusd => 1.5947, usdcad => 0.9929, |
37
|
|
|
|
|
|
|
usdsek => 6.6491, usdchf => 0.9331); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Just exports an 'usdx' subroutine that returns the current USDX value. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 usdx |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
If called without arguments, returns the "current" USDX value using |
46
|
|
|
|
|
|
|
data from YAHOO finance website, using Finance::Quote module. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
If called with argument, then the hashtable must have six key/value |
49
|
|
|
|
|
|
|
pairs, with rates for currency convertion. Note that two of the keys |
50
|
|
|
|
|
|
|
are not usd->other convertions. All exact keys are required. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub usdx { |
55
|
2
|
|
|
2
|
1
|
12
|
my ($eurusd, $usdjpy, $gbpusd, $usdcad, $usdsek, $usdchf); |
56
|
2
|
|
|
|
|
9
|
my @keys = qw(eurusd usdjpy gbpusd usdcad usdsek usdchf); |
57
|
2
|
50
|
|
|
|
6
|
if (@_) { |
58
|
2
|
|
|
|
|
17
|
my %values = @_; |
59
|
2
|
|
|
|
|
4
|
for my $k (@keys) { |
60
|
12
|
50
|
|
|
|
28
|
die "Call to 'usdx' misses key '$k'" unless exists($values{$k}); |
61
|
12
|
|
|
|
|
573
|
eval "\$$k = \$values{\$k};" |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
0
|
my $q = Finance::Quote->new; |
65
|
0
|
|
|
|
|
0
|
$eurusd = $q->currency('EUR' => 'USD'); |
66
|
0
|
|
|
|
|
0
|
$usdjpy = $q->currency('USD' => 'JPY'); |
67
|
0
|
|
|
|
|
0
|
$gbpusd = $q->currency('GBP' => 'USD'); |
68
|
0
|
|
|
|
|
0
|
$usdcad = $q->currency('USD' => 'CAD'); |
69
|
0
|
|
|
|
|
0
|
$usdsek = $q->currency('USD' => 'SEK'); |
70
|
0
|
|
|
|
|
0
|
$usdchf = $q->currency('USD' => 'CHF'); |
71
|
|
|
|
|
|
|
} |
72
|
2
|
|
|
|
|
16717
|
my $usdx = 50.14348112 * $eurusd**(-0.576) * $usdjpy**(0.136) * $gbpusd**(-0.119) * $usdcad**(0.091) * $usdsek**(0.042) * $usdchf**(0.036); |
73
|
2
|
|
|
|
|
50
|
return $usdx; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Alberto Simões, C<< >> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 BUGS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Please report any bugs or feature requests to C
|
83
|
|
|
|
|
|
|
rt.cpan.org>, or through the web interface at |
84
|
|
|
|
|
|
|
L. I |
85
|
|
|
|
|
|
|
will be notified, and then you'll automatically be notified of |
86
|
|
|
|
|
|
|
progress on your bug as I make changes. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SUPPORT |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
perldoc Finance::USDX |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
You can also look for information at: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over 4 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * CPAN Ratings |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * Search CPAN |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Copyright 2012 Alberto Simões. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
121
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
122
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; # End of Finance::USDX |