GeniusTrader/Analyzers.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 125 CC 6 SCAR 20.4
CC
6
Cov
0%
new
30.0
calculate_interval
6.0
get_registered_object
2.0
CRAP 7.7
1 package Finance::GeniusTrader::Analyzers;
2  
3 # Copyright 2004 Oliver Bossert
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 use strict;
8 use vars qw(@ISA %OBJECT_REPOSITORY);
9  
10 require Exporter;
11 @ISA = qw(Exporter Finance::GeniusTrader::Dependency);
12  
13 use Finance::GeniusTrader::Prices;
14 use Finance::GeniusTrader::Calculator;
15 use Finance::GeniusTrader::Registry;
16 use Finance::GeniusTrader::Dependency;
17 use Finance::GeniusTrader::Portfolio;
18 use Finance::GeniusTrader::Portfolio::Order;
19 use Finance::GeniusTrader::Conf;
20 use Finance::GeniusTrader::Eval;
21 use Finance::GeniusTrader::DateTime;
22 use Finance::GeniusTrader::ArgsTree;
23  
24 =head1 NAME
25  
26 Finance::GeniusTrader::Analyzers - Provides some functions that will be used by all analyzer modules.
27  
28 =head1 DESCRIPTION
29  
30  
31 =head2 MANAGE A REPOSITORY OF INDICATORS
32  
33 Finance::GeniusTrader::Analyzers::get_registered_object($name);
34 Finance::GeniusTrader::Analyzers::register_object($name, $object);
35 Finance::GeniusTrader::Analyzers::get_or_register_object($name, $object);
36 Finance::GeniusTrader::Analyzers::manage_object(\@NAMES, $object, $class, $args, $key);
37  
38 =cut
39  
40 sub get_registered_object {
41 Finance::GeniusTrader::Registry::get_registered_object(\%OBJECT_REPOSITORY, @_);
42 }
43 sub register_object {
44 Finance::GeniusTrader::Registry::register_object(\%OBJECT_REPOSITORY, @_);
45 }
46 sub get_or_register_object {
47 Finance::GeniusTrader::Registry::get_or_register_object(\%OBJECT_REPOSITORY, @_);
48 }
49 sub manage_object {
50 Finance::GeniusTrader::Registry::manage_object(\%OBJECT_REPOSITORY, @_);
51 }
52  
53  
54 =head2 DEFAULT FUNCTIONS FOR ANALYZERS
55  
56 =over
57  
58 =item C<< Finance::GeniusTrader::Analyzers::Module->new($args, $key, $func) >>
59  
60 Create a new analyzer with the given arguments. $key and $func are optional,
61 they are useful for indicators which can use non-usual input streams.
62  
63 =cut
64 sub new {
65 my ($type, $args, $key, $func) = @_;
66 my $class = ref($type) || $type;
67  
68 no strict "refs";
69
70 my $self = { };
71 if (defined($args)) {
72 if ( $#{$args} < $#{"$class\::DEFAULT_ARGS"} ) {
73 for (my $n=($#{$args}+1); $n<=$#{"$class\::DEFAULT_ARGS"}; $n++) {
74 push @{$args}, ${"$class\::DEFAULT_ARGS"}[$n];
75 }
76 }
77 $self->{'args'} = Finance::GeniusTrader::ArgsTree->new(@{$args});
78 } elsif (defined (@{"$class\::DEFAULT_ARGS"})) {
79 $self->{'args'} = Finance::GeniusTrader::ArgsTree->new(@{"$class\::DEFAULT_ARGS"});
80 } else {
81 $self->{'args'} = Finance::GeniusTrader::ArgsTree->new(); # no args
82 }
83  
84 if (defined($func)) {
85 $self->{'func'} = $func;
86 }
87  
88 return manage_object(\@{"$class\::NAMES"}, $self, $class, $self->{'args'}, $key);
89 }
90  
91  
92  
93  
94 =item C<< $analyzers->initialize() >>
95  
96 Default method that does nothing.
97  
98 =back
99  
100 =cut
101  
102 sub initialize { 1; }
103  
104 sub calculate_interval {
105 my ($self, $calc, $first, $last) = @_;
106  
107 if (ref($self->{'args'}) =~ /Finance::GeniusTrader::ArgsTree/) {
108 $self->{'args'}->prepare_interval($calc, $first, $last);
109 }
110 for (my $i = $first; $i <= $last; $i++)
111 {
112 $self->calculate($calc, $i);
113 }
114 }
115  
116  
117 1;