GeniusTrader/MoneyManagement/Basic.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 65 CC 7 SCAR 31.2
CC
7
Cov
0%
manage_quantity
42.0
new
6.0
BEGIN
2.0
CRAP 22.7
1 package Finance::GeniusTrader::MoneyManagement::Basic;
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 = ("Basic");
14 @ISA = qw(Finance::GeniusTrader::MoneyManagement);
15  
16 =head1 Finance::GeniusTrader::MoneyManagement::Basic
17  
18 Basic and dumb money management rules. Invest all cash available (provided
19 that no marged position block the cash - in this money management rule
20 each dollar invested in marged position requires 1 dollar in cash).
21  
22 =cut
23 sub new {
24 my $type = shift;
25 my $class = ref($type) || $type;
26 my $args = shift;
27
28 my $self = { 'args' => defined($args) ? $args : [] };
29
30 return manage_object(\@NAMES, $self, $class, $self->{'args'}, '');
31 }
32  
33 sub manage_quantity {
34 my ($self, $order, $i, $calc, $portfolio) = @_;
35
36 my $date = $calc->prices->at($i)->[$DATE];
37 if ($portfolio->has_historic_evaluation($date)) {
38 my ($cash, $eval, $gains, $minvest) = $portfolio->get_historic_evaluation($date);
39 my $avail = $cash + $gains - $minvest;
40 foreach my $pos ($portfolio->list_open_positions()) {
41 # Tread marged positions like usual position
42 if ($pos->being_closed()) {
43 $avail += $portfolio->{'position_evaluation'}{$pos->id};
44 # Note that we forget cash needed to pay the close order
45 # but hey ... we're already not sure of tomorrow's
46 # evaluation.
47 }
48 }
49 my $price = (defined($order->{'price'})) ? $order->{'price'} : $calc->prices->at($i)->[$LAST];
50 if ($avail > $price) {
51 return int($avail / $price);
52 } else {
53 return 0;
54 }
55 }
56 # No way to decide following our rules
57 if (defined($order->{'quantity'}) &&
58 $order->{'quantity'})
59 {
60 return $order->{'quantity'};
61 }
62 return 0;
63
64 }
65