GeniusTrader/MoneyManagement/ShareMultiples.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 16 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 / 66 CC 9 SCAR 31.9
CC
9
Cov
0%
manage_quantity
42.0
new
20.0
BEGIN
2.0
CRAP 24.3
1 package Finance::GeniusTrader::MoneyManagement::ShareMultiples;
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 = ("ShareMultiples[#1, #2]");
14 @ISA = qw(Finance::GeniusTrader::MoneyManagement);
15  
16 =head1 Finance::GeniusTrader::MoneyManagement::ShareMultiples
17  
18 =head2 Overview
19  
20 This money management rule will provide you a tool to buy/sell round lots
21 of shares (ie: multiples of 5, 10 or 50).
22  
23 =head2 Parameters
24  
25 By default, the first parameter is initialized to 10 and will provide
26 share multiples of 10 stocks. The second option is set up to zero and
27 represent the calculation method, but look at all options :
28  
29 0 : round to the nearest multiple
30 1 : round to the lower multiple
31 2 : round to the upper multiple
32  
33 =cut
34  
35 sub new {
36 my $type = shift;
37 my $class = ref($type) || $type;
38 my $args = shift;
39
40 my $self = { 'args' => defined($args) ? $args : [ 10, 0 ] };
41  
42 $args->[0] = 10 if (! defined($args->[0]));
43 $args->[1] = 0 if (! defined($args->[1]));
44
45 return manage_object(\@NAMES, $self, $class, $self->{'args'}, '');
46 }
47  
48 sub manage_quantity {
49 my ($self, $order, $i, $calc, $portfolio) = @_;
50 my $multiple = $self->{'args'}[0];
51 my $calculation_method = $self->{'args'}[1];
52
53 if (defined($order->{'quantity'})) {
54  
55 my $round_quantity = int($order->{'quantity'} / $multiple) * $multiple;
56 my $remains = $order->{'quantity'} - $round_quantity;
57
58 if ($calculation_method eq 0) {
59 if ($remains >= ($multiple / 2)) {
60 return ($round_quantity + $multiple);
61 } else {
62 return $round_quantity;
63 }
64 }
65 if ($calculation_method eq 1) {
66 return $round_quantity;
67 }
68 if ($calculation_method eq 2) {
69 return ($round_quantity + $multiple);
70 }
71 }
72 }
73  
74 1;