GeniusTrader/MoneyManagement/FixedFractional.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 4 SCAR 18.3
CC
4
Cov
0%
new
12.0
manage_quantity
6.0
BEGIN
2.0
CRAP 6.2
1 package Finance::GeniusTrader::MoneyManagement::FixedFractional;
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(@NAMES @ISA);
9  
10 use Finance::GeniusTrader::MoneyManagement;
11 use Finance::GeniusTrader::Prices;
12  
13 @NAMES = ("FixedFractional[#1]");
14 @ISA = qw(Finance::GeniusTrader::MoneyManagement);
15  
16 =head1 Finance::GeniusTrader::MoneyManagement::FixedFractional
17  
18 =head2 Overview
19  
20 This money management rule will allowed to each trade a fixed fraction of
21 the current portfolio value.
22  
23 =cut
24  
25 sub new {
26 my $type = shift;
27 my $class = ref($type) || $type;
28 my $args = shift;
29
30 my $self = { 'args' => defined($args) ? $args : [ 100 ] };
31  
32 $args->[0] = 100 if (! defined($args->[0]));
33
34 return manage_object(\@NAMES, $self, $class, $self->{'args'}, '');
35 }
36  
37 sub manage_quantity {
38 my ($self, $order, $i, $calc, $portfolio) = @_;
39 my $ratio = $self->{'args'}[0] / 100;
40  
41 # Initialization of portfolio value
42 my $cash = $portfolio->current_cash;
43 my $positions = $portfolio->current_evaluation;
44 my $upcoming_gains_or_losses = $portfolio->current_marged_gains;
45 my $portfolio_value = $cash + $positions + $upcoming_gains_or_losses;
46  
47 if ($order->{'price'}) {
48 return int(($portfolio_value * $ratio) / $order->{'price'});
49 } else {
50 return int(($portfolio_value * $ratio) / $calc->prices->at($i)->[$LAST]);
51 }
52 }
53  
54 1;