GeniusTrader/CloseStrategy/Stop/Fixed.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 64 CC 3 SCAR 11.7
CC
3
Cov
0%
get_indicative_long_stop
6.0
get_indicative_short_stop
6.0
initialize
2.0
CRAP 3.2
1 package Finance::GeniusTrader::CloseStrategy::Stop::Fixed;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # Modified 2004 by Oliver Bossert
5 # This file is distributed under the terms of the General Public License
6 # version 2 or (at your option) any later version.
7  
8 # Standards-Version: 1.0
9  
10 use strict;
11 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
12  
13 use Finance::GeniusTrader::CloseStrategy;
14 use Finance::GeniusTrader::Prices;
15  
16 @ISA = qw(Finance::GeniusTrader::CloseStrategy);
17 @NAMES = ("StopFixed[#1]");
18 @DEFAULT_ARGS = (4);
19  
20 =head1 Finance::GeniusTrader::CloseStrategy::Stop::Fixed
21  
22 This strategy closes the position once the prices have crossed a limit
23 called stop. This stop is defined as a percentage from the initial price.
24 The limit is parameterized. By default it's 4%.
25  
26 =cut
27  
28 sub initialize {
29 my ($self) = @_;
30 }
31  
32 sub get_indicative_long_stop {
33 my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_;
34 my $stop = 0;
35 $self->{'long_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
36 if ($order->price)
37 {
38 $stop = $order->price * $self->{'long_factor'};
39 } else {
40 $stop = $calc->prices->at($i)->[$LAST] * $self->{'long_factor'};
41 }
42 return $stop;
43 }
44  
45 sub get_indicative_short_stop {
46 my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_;
47 my $stop = 0;
48 $self->{'short_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
49 if ($order->price)
50 {
51 $stop = $order->price * $self->{'short_factor'};
52 } else {
53 $stop = $calc->prices->at($i)->[$LAST] * $self->{'short_factor'};
54 }
55 return $stop;
56 }
57  
58 sub long_position_opened {
59 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
60  
61 $self->{'long_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
62 $position->set_stop($position->open_price * $self->{'long_factor'});
63
64 return;
65 }
66  
67 sub short_position_opened {
68 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
69  
70 $self->{'short_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
71 $position->set_stop($position->open_price * $self->{'short_factor'});
72  
73 return;
74 }
75  
76 sub manage_long_position {
77 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
78  
79 return;
80 }
81  
82 sub manage_short_position {
83 my ($self, $calc, $i, $position, $ps_manager, $sys_manager) = @_;
84
85 return;
86 }
87