GeniusTrader/TradeFilters.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 91 CC 4 SCAR 17.9
CC
4
Cov
0%
new
20.0
accept_trade
2.0
precalculate_all
2.0
CRAP 6.0
1 package Finance::GeniusTrader::TradeFilters;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
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 @EXPORT %OBJECT_REPOSITORY);
9  
10 require Exporter;
11 @ISA = qw(Exporter Finance::GeniusTrader::Dependency);
12 @EXPORT = qw(&build_object_name &manage_object);
13  
14 use Finance::GeniusTrader::Registry;
15 use Finance::GeniusTrader::Dependency;
16 #ALL# use Log::Log4perl qw(:easy);
17  
18 =head1 NAME
19  
20 Finance::GeniusTrader::TradeFilters - Filters to accept or refuse trades
21  
22 =head1 DESCRIPTION
23  
24 Trade filters are used to decide whether or not a trade is accepted.
25 It can for example refuse trade going against the current trend.
26 You can use several trade filters simultaneously.
27  
28 =over
29  
30 =item C<< $filter->accept_trade($order, $i, $calc, $portfolio) >>
31  
32 =cut
33 sub accept_trade {
34 my ($self, $order, $i, $calc, $portfolio) = @_;
35
36 # Automatically accept
37 return 1;
38 }
39  
40 =item C<< $system->precalculate_all($calc) >>
41  
42 =item C<< $system->precalculate_interval($calc, $first, $last) >>
43  
44 If you run a system on a long period of time you may want to precalculate
45 all the indicators in order to benefit of possible optimizations. This is
46 the role of those 2 functions.
47  
48 =cut
49 # Helper functions to optimize calculations
50 sub precalculate_all {
51 my ($self, $calc) = @_;
52 $self->precalculate_interval($calc, 0, $calc->prices->count - 1);
53 return;
54 }
55 sub precalculate_interval {
56 my ($self, $calc, $first, $last) = @_;
57 # Can do nothing, I don't know which indicators are used
58 # This function must be overrident by specific trade filters
59 return;
60 }
61  
62  
63 # Default initialize that does nothing
64 sub initialize { 1 }
65  
66 # Finance::GeniusTrader::Registry functions
67 sub get_registered_object {
68 Finance::GeniusTrader::Registry::get_registered_object(\%OBJECT_REPOSITORY, @_);
69 }
70 sub register_object {
71 Finance::GeniusTrader::Registry::register_object(\%OBJECT_REPOSITORY, @_);
72 }
73 sub get_or_register_object {
74 Finance::GeniusTrader::Registry::get_or_register_object(\%OBJECT_REPOSITORY, @_);
75 }
76 sub manage_object {
77 Finance::GeniusTrader::Registry::manage_object(\%OBJECT_REPOSITORY, @_);
78 }
79  
80 sub new {
81 my ($type, $args, $key) = @_;
82 my $class = ref($type) || $type;
83  
84 no strict "refs";
85
86 my $self = { };
87 if (defined($args)) {
88 if ( $#{$args} < $#{"$class\::DEFAULT_ARGS"} ) {
89 for (my $n=($#{$args}+1); $n<=$#{"$class\::DEFAULT_ARGS"}; $n++) {
90 push @{$args}, ${"$class\::DEFAULT_ARGS"}[$n];
91 }
92 }
93 $self->{'args'} = Finance::GeniusTrader::ArgsTree->new(@{$args});
94 } elsif (defined (@{"$class\::DEFAULT_ARGS"})) {
95 $self->{'args'} = Finance::GeniusTrader::ArgsTree->new(@{"$class\::DEFAULT_ARGS"});
96 } else {
97 $self->{'args'} = Finance::GeniusTrader::ArgsTree->new(); # no args
98 }
99  
100 return manage_object(\@{"$class\::NAMES"}, $self, $class, $self->{'args'}, $key);
101 }
102  
103  
104 =back
105  
106 =cut
107 1;