| 1 | package Finance::GeniusTrader::Systems::Generic; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # Modified 2004 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 | use strict; | ||
| 9 | use vars qw(@ISA @NAMES); | ||
| 10 | |||
| 11 | use Finance::GeniusTrader::Prices; | ||
| 12 | use Finance::GeniusTrader::Systems; | ||
| 13 | use Finance::GeniusTrader::Eval; | ||
| 14 | use Finance::GeniusTrader::Tools qw(:generic); | ||
| 15 | |||
| 16 | @ISA = qw(Finance::GeniusTrader::Systems); | ||
| 17 | @NAMES = ("Generic[#*]"); | ||
| 18 | |||
| 19 | =head1 Generic System module | ||
| 20 | |||
| 21 | a system runs on two signals: long and short | ||
| 22 | |||
| 23 | these terms imply buying shares when the long signal is triggered | ||
| 24 | and selling shares short when the short signal is triggered. in | ||
| 25 | either case a new position is thus opened (or maybe added to) | ||
| 26 | for the security that caused the signal. | ||
| 27 | |||
| 28 | a generic system description requires two signals, the first | ||
| 29 | must define the long signal, the second defines the short signal. | ||
| 30 | |||
| 31 | out on a limb here -- a system description can specify only | ||
| 32 | one long and one short signal | ||
| 33 | |||
| 34 | nb: the short signal will not necessarily close a position | ||
| 35 | opened by a prior long signal. open position management is | ||
| 36 | controlled by a close strategy. | ||
| 37 | |||
| 38 | according to Finance::GeniusTrader::Systems a signal is acted upon in the following | ||
| 39 | day (timeframe). if a position is opened (long or short) closing | ||
| 40 | that position is controlled by a close strategy (CS). therefore, | ||
| 41 | most system descriptions will also include a close strategy | ||
| 42 | description. | ||
| 43 | |||
| 44 | system description can specify multiple close strategies | ||
| 45 | |||
| 46 | system description can specify multiple money management (MM) | ||
| 47 | strategies | ||
| 48 | |||
| 49 | how does OrderFactory (OF) fit in with system description? | ||
| 50 | |||
| 51 | |||
| 52 | =head1 Generic System Examples | ||
| 53 | |||
| 54 | SY:Generic \ | ||
| 55 | {S:Generic:CrossOverUp {I:SMA 20 {I:Prices CLOSE}} {I:SMA 60 {I:Prices CLOSE}}} \ | ||
| 56 | {S:Generic:CrossOverDown {I:SMA 20 {I:Prices CLOSE}} {I:SMA 60 {I:Prices CLOSE}}} \ | ||
| 57 | | TF:OneTrade \ | ||
| 58 | | CS:OppositeSignal | ||
| 59 | |||
| 60 | the CrossOverUp signal denotes the buy condition | ||
| 61 | the CrossOverDown signal denotes the sell condition | ||
| 62 | |||
| 63 | notice that the close strategy explicitly specifies that the short | ||
| 64 | signal is also used to close open positions, and conversely | ||
| 65 | short positions are closed with the long signal. | ||
| 66 | |||
| 67 | the trade filter (TF) (see perldoc ../GT/TradeFilters.pm) will limit | ||
| 68 | the number of open positions (either long or short) to one, however | ||
| 69 | it will allow a new open position and a closed postion in the same timeframe. | ||
| 70 | |||
| 71 | system descriptions can specify multiple trade filters | ||
| 72 | |||
| 73 | |||
| 74 | SY:Generic inherits new from Finance::GeniusTrader::Systems:: | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | |||
| 79 | sub initialize { | ||
| 80 | my ($self) = @_; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub precalculate_interval { | ||
| 84 | my ($self, $calc, $first, $last) = @_; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub long_signal { | ||
| 88 | my ($self, $calc, $i) = @_; | ||
| 89 | |||
| 90 | return 0 if (! $self->check_dependencies($calc, $i)); | ||
| 91 | |||
| 92 | if ( $self->{'args'}->get_arg_values($calc, $i, 1) == 1 ) | ||
| 93 | { | ||
| 94 | return 1; | ||
| 95 | } | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | sub short_signal { | ||
| 100 | my ($self, $calc, $i) = @_; | ||
| 101 | |||
| 102 | return 0 if (! $self->check_dependencies($calc, $i)); | ||
| 103 | |||
| 104 | if ( $self->{'args'}->get_nb_args() >= 2 && | ||
| 105 | $self->{'args'}->get_arg_values($calc, $i, 2) == 1 ) | ||
| 106 | { | ||
| 107 | return 1; | ||
| 108 | } | ||
| 109 | return 0; | ||
| 110 | } | ||
| 111 | |||
| 112 | 1; |