« GeniusTrader/CloseStrategy/OppositeSignal.pm
↑ Summary
GeniusTrader/CloseStrategy/PartialStop.pm »
| 1 | package Finance::GeniusTrader::CloseStrategy::PartialGain; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # Modified 2004 by Oliver Bossert | ||
| 5 | # This file is distributed under the terms of the General Public License | ||
| 6 | # version 2 or (at your option) any later version. | ||
| 7 | |||
| 8 | # Standards-Version: 1.0 | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 12 | |||
| 13 | use Finance::GeniusTrader::CloseStrategy; | ||
| 14 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::CloseStrategy); | ||
| 16 | @NAMES = ("PartialGain[#1, #2]"); | ||
| 17 | @DEFAULT_ARGS = (10, 0.5); | ||
| 18 | |||
| 19 | =head1 Finance::GeniusTrader::CloseStrategy::PartialGain | ||
| 20 | |||
| 21 | This strategy partialy closes the position once the prices have crossed a | ||
| 22 | limit called stop. This stop is defined as a percentage from the initial | ||
| 23 | price. By default, it's defined as + 10 %. The ratio of the position is | ||
| 24 | parameterized. By default it's half the initial position (0.5). | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | sub initialize { | ||
| 29 | my ($self) = @_; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub long_position_opened { | ||
| 33 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 34 | |||
| 35 | $self->{'long_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 1) / 100; | ||
| 36 | my $ratio = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 37 | |||
| 38 | if (($ratio > 0) and ($ratio <= 1)) { | ||
| 39 | my $order = $pf_manager->sell_limited_price($calc, | ||
| 40 | $position->source, | ||
| 41 | $position->open_price * $self->{'long_factor'}); | ||
| 42 | $order->set_not_discardable; | ||
| 43 | $pf_manager->set_order_partial($order, $ratio, $position); | ||
| 44 | $pf_manager->submit_order_in_position($position, $order, $i, $calc); | ||
| 45 | } | ||
| 46 | |||
| 47 | return; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub short_position_opened { | ||
| 51 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 52 | |||
| 53 | $self->{'short_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 1) / 100; | ||
| 54 | my $ratio = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 55 | |||
| 56 | if (($ratio > 0) and ($ratio <= 1)) { | ||
| 57 | my $order = $pf_manager->buy_limited_price($calc, | ||
| 58 | $position->source, | ||
| 59 | $position->open_price * $self->{'short_factor'}); | ||
| 60 | $order->set_not_discardable; | ||
| 61 | $pf_manager->set_order_partial($order, $ratio, $position); | ||
| 62 | $pf_manager->submit_order_in_position($position, $order, $i, $calc); | ||
| 63 | } | ||
| 64 | |||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | sub manage_long_position { | ||
| 69 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 70 | |||
| 71 | return; | ||
| 72 | } | ||
| 73 | |||
| 74 | sub manage_short_position { | ||
| 75 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 76 | |||
| 77 | return; | ||
| 78 | } | ||
| 79 |