GeniusTrader/OrderFactory/StopOnExtreme.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 48 CC 5 SCAR 18.2
CC
5
Cov
0%
initialize
12.0
create_buy_order
6.0
create_sell_order
6.0
CRAP 6.2
1 package Finance::GeniusTrader::OrderFactory::StopOnExtreme;
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 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::OrderFactory;
13 use Finance::GeniusTrader::Prices;
14  
15 @ISA = qw(Finance::GeniusTrader::OrderFactory);
16 @NAMES = ("StopOnExtreme[#1,#2]");
17 @DEFAULT_ARGS = (0.5, 1);
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::OrderFactory::StopOnExtreme
22  
23 =head1 DESCRIPTION
24  
25 Create a "stop" order that will with the limit the high of the day (modulo
26 x%) for a long position and the low of the day for a short position.
27  
28 =cut
29 sub initialize {
30 my ($self) = @_;
31 $self->add_arg_dependency(1, 1) unless $self->{'args'}->is_constant(1);
32 $self->add_arg_dependency(2, 1) unless $self->{'args'}->is_constant(2);
33 }
34  
35 sub create_buy_order {
36 my ($self, $calc, $i, $sys_manager, $pf_manager) = @_;
37
38 return if (! $self->check_dependencies($calc, $i));
39  
40 $self->{'long_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
41 $self->{'long_second'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 2) / 100;
42
43 my $stop = $calc->prices->at($i)->[$HIGH] * $self->{'long_factor'};
44 return $pf_manager->buy_conditional($calc, $sys_manager->get_name,
45 $stop, $stop * $self->{'long_second'});
46 }
47  
48 sub create_sell_order {
49 my ($self, $calc, $i, $sys_manager, $pf_manager) = @_;
50  
51 return if (! $self->check_dependencies($calc, $i));
52
53 $self->{'short_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
54 $self->{'short_second'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 2) / 100;
55
56 my $stop = $calc->prices->at($i)->[$LOW] * $self->{'short_factor'};
57 return $pf_manager->sell_conditional($calc, $sys_manager->get_name,
58 $stop, $stop * $self->{'short_second'});
59 }
60  
61 1;