| 1 | package Finance::GeniusTrader::MoneyManagement::STO; | ||
| 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::Indicators::STO; | ||
| 12 | use Finance::GeniusTrader::Prices; | ||
| 13 | use Finance::GeniusTrader::Portfolio; | ||
| 14 | |||
| 15 | @NAMES = ("STO"); | ||
| 16 | @ISA = qw(Finance::GeniusTrader::MoneyManagement); | ||
| 17 | |||
| 18 | =head1 Finance::GeniusTrader::MoneyManagement::STO | ||
| 19 | |||
| 20 | =head2 Overview | ||
| 21 | |||
| 22 | This new money management technique utilize the Stochastics (STO) in order | ||
| 23 | to improve the performance of trend-following trading. | ||
| 24 | |||
| 25 | =head2 References | ||
| 26 | |||
| 27 | "A New Money Management Technique" - Takehide Matoba | ||
| 28 | Article found in http://www.erivativesreview.com | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | sub new { | ||
| 33 | my $type = shift; | ||
| 34 | my $class = ref($type) || $type; | ||
| 35 | my $args = shift; | ||
| 36 | |||
| 37 | my $self = { 'args' => defined($args) ? $args : [] }; | ||
| 38 | |||
| 39 | return manage_object(\@NAMES, $self, $class, $self->{'args'}, ''); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub initialize { | ||
| 43 | my $self = shift; | ||
| 44 | |||
| 45 | $self->{'sto'} = Finance::GeniusTrader::Indicators::STO->new([ 10 ]); | ||
| 46 | $self->add_indicator_dependency($self->{'sto'}, 1); | ||
| 47 | } | ||
| 48 | |||
| 49 | sub manage_quantity { | ||
| 50 | my ($self, $order, $i, $calc, $portfolio) = @_; | ||
| 51 | my $indic = $calc->indicators; | ||
| 52 | my $sto_name = $self->{'sto'}->get_name(3); | ||
| 53 | my $factor = 0; | ||
| 54 | |||
| 55 | return if (! $self->check_dependencies($calc, $i)); | ||
| 56 | |||
| 57 | if (defined($order->quantity)) { | ||
| 58 | |||
| 59 | my $sto = $indic->get($sto_name, $i); | ||
| 60 | |||
| 61 | if ($order->is_buy_order) { | ||
| 62 | $factor = (100 - $sto) / 100; | ||
| 63 | } | ||
| 64 | if ($order->is_sell_order) { | ||
| 65 | $factor = $sto / 100; | ||
| 66 | } | ||
| 67 | return int($order->quantity * $factor); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; |