| 1 | package Finance::GeniusTrader::MoneyManagement::FixedSum; | ||
| 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 = ("FixedSum[#1]"); | ||
| 14 | @ISA = qw(Finance::GeniusTrader::MoneyManagement); | ||
| 15 | |||
| 16 | =head1 Finance::GeniusTrader::MoneyManagement::FixedSum | ||
| 17 | |||
| 18 | =head2 Overview | ||
| 19 | |||
| 20 | This money management rule will invest the same amount of money in each | ||
| 21 | trade. The default value is set up to 1000. | ||
| 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 : [ 1000 ] }; | ||
| 31 | |||
| 32 | $args->[0] = 1000 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 $investment = $self->{'args'}[0]; | ||
| 40 | |||
| 41 | if (!defined($order->{'quantity'})) { | ||
| 42 | if ($order->{'price'}) { | ||
| 43 | return int($investment / $order->{'price'}); | ||
| 44 | } else { | ||
| 45 | return int($investment / $calc->prices->at($i)->[$LAST]); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; |