GeniusTrader/CloseStrategy/Systems/TFS.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 65 CC 4 SCAR 13.9
CC
4
Cov
0%
new
6.0
manage_long_position
6.0
manage_short_position
6.0
CRAP 4.0
1 package Finance::GeniusTrader::CloseStrategy::Systems::TFS;
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 @NAMES);
9  
10 use Finance::GeniusTrader::Prices;
11 use Finance::GeniusTrader::CloseStrategy;
12 use Finance::GeniusTrader::Indicators::TETHER;
13  
14 @ISA = qw(Finance::GeniusTrader::CloseStrategy);
15 @NAMES = ("TFS[#1]");
16  
17 =head1 CloseStrategy of Trend Following System (TFS)
18  
19 =cut
20 sub new {
21 my $type = shift;
22 my $class = ref($type) || $type;
23 my $args = shift;
24  
25 my $self = { "args" => defined($args) ? $args : [50] };
26  
27 return manage_object(\@NAMES, $self, $class, $self->{'args'}, "");
28 }
29  
30 sub initialize {
31 my ($self) = @_;
32  
33 $self->{'tether'} = Finance::GeniusTrader::Indicators::TETHER->new([ $self->{'args'}[0] ]);
34  
35 $self->add_indicator_dependency($self->{'tether'}, 2);
36 $self->add_prices_dependency(1);
37 }
38  
39  
40 sub manage_long_position {
41 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
42  
43 $self->{'tether'}->calculate($calc, $i);
44
45 # Eventually close the position or invert it
46 if ($calc->prices->at($i)->[$CLOSE] <
47 $calc->indicators->get($self->{'tether'}->get_name, $i))
48 {
49 my $order = $pf_manager->sell_market_price($calc,
50 $sys_manager->get_name);
51 $pf_manager->submit_order_in_position($position, $order, $i, $calc);
52 }
53 return;
54 }
55  
56 sub manage_short_position {
57 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
58
59 $self->{'tether'}->calculate($calc, $i);
60  
61 if ($calc->prices->at($i)->[$CLOSE] >
62 $calc->indicators->get($self->{'tether'}->get_name, $i))
63 {
64 my $order = $pf_manager->buy_market_price($calc,
65 $sys_manager->get_name);
66 $pf_manager->submit_order_in_position($position, $order, $i, $calc);
67 }
68 return;
69 }
70