GeniusTrader/Indicators/Prices.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 76 CC 12 SCAR 39.1
CC
12
Cov
0%
initialize
90.0
calculate
20.0
BEGIN
2.0
CRAP 50.0
1 package Finance::GeniusTrader::Indicators::Prices;
2  
3 # Copyright 2000-2003 Raphaƫl Hertzog
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES);
11  
12 use Finance::GeniusTrader::Indicators;
13 use Finance::GeniusTrader::Prices;
14 use Finance::GeniusTrader::Eval;
15  
16 @ISA = qw(Finance::GeniusTrader::Indicators);
17 @NAMES = ("Prices[#*]");
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::Indicators::Prices - Return the prices/volume/date of any share
22  
23 =head1 DESCRIPTION
24  
25 As you often need the prices while using Generic indicators, this
26 modules makes it easy for you to include prices through an indicator:
27 {I:Prices OPEN} or {I:Prices LOW 13330}
28  
29 =head1 PARAMETERS
30  
31 =over
32  
33 =item Data
34  
35 You have to tell in which data you're interested. You have to choose between
36 OPEN, HIGH, LOW, CLOSE, VOLUME, DATE.
37  
38 =item Share
39  
40 If you don't specify a second argument, you will use the data of the share
41 that you're working on. But sometimes you may want to use the prices of a
42 second share (for comparison, etc). In that case you can specify its code.
43  
44 =back
45  
46 =cut
47 sub initialize {
48 my $self = shift;
49 my $data = $CLOSE;
50
51 # First parameter: which data
52 if ($self->{'args'}->get_nb_args() > 0) {
53 my $arg = $self->{'args'}->get_arg_constant(1);
54 if ($arg =~ /OPEN|FIRST/i) { $data = $OPEN }
55 elsif ($arg =~ /HIGH/i) { $data = $HIGH }
56 elsif ($arg =~ /LOW/i) { $data = $LOW }
57 elsif ($arg =~ /CLOSE|LAST/i) { $data = $CLOSE }
58 elsif ($arg =~ /VOLUME/i) { $data = $VOLUME }
59 elsif ($arg =~ /DATE/i) { $data = $DATE }
60 }
61
62 # Second parameter: code of the share
63 if ($self->{'args'}->get_nb_args() > 1) {
64 $self->{'use_std_prices'} = 0;
65 my $db = create_db_object();
66 my $q = $db->get_prices($self->{'args'}->get_arg_constant(2));
67 $self->{'special_prices'} = $q;
68 } else {
69 $self->{'use_std_prices'} = 1;
70 }
71  
72 # Misc init
73 $self->{'data_ind'} = $data;
74 }
75  
76 sub calculate {
77 my ($self, $calc, $i) = @_;
78  
79 return if ($calc->indicators->is_available($self->get_name, $i));
80  
81 my $indic = $calc->indicators;
82 my $DATA = $self->{'data_ind'};
83
84 if ($self->{'use_std_prices'}) {
85 $indic->set($self->get_name, $i, $calc->prices->at($i)->[$DATA]);
86 } else {
87 my $prices = $self->{'special_prices'};
88 my $date = $calc->prices->at($i)->[$DATE];
89 if ($prices->has_date($date)) {
90 $indic->set($self->get_name, $i, $prices->at_date($date)->[$DATA]);
91 }
92 }
93 }
94  
95 1;