| 1 | package Finance::GeniusTrader::Indicators::ROC; | ||
| 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 | # Standards-Version: 1.0 | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Indicators; | ||
| 13 | |||
| 14 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 15 | @NAMES = ("ROC[#1,#2]"); | ||
| 16 | @DEFAULT_ARGS = (12,"{I:Prices CLOSE}"); | ||
| 17 | |||
| 18 | =head2 Finance::GeniusTrader::Indicators::ROC | ||
| 19 | |||
| 20 | The Rate of Change (ROC) is similar to the Momentum. | ||
| 21 | The standard Rate of Change is the ROC 12 days : Finance::GeniusTrader::Indicators::MOM->new() | ||
| 22 | If you need a non standard Momentum use for example : Finance::GeniusTrader::Indicators::MOM->new([9]) or Finance::GeniusTrader::Indicators::MOM->new([25]) | ||
| 23 | |||
| 24 | =head2 Validation | ||
| 25 | |||
| 26 | This Indicator was validated by the data available from comdirect.de: | ||
| 27 | The DAX at 04.06.2003 (data from yahoo.com) had a ROC of 8.05. | ||
| 28 | This is consistent with this indicator: 8.0451 | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | sub intialize { | ||
| 33 | my ($self) = @_; | ||
| 34 | } | ||
| 35 | |||
| 36 | =head2 Finance::GeniusTrader::Indicators::ROC::calculate($calc, $day) | ||
| 37 | |||
| 38 | =cut | ||
| 39 | sub calculate { | ||
| 40 | my ($self, $calc, $i) = @_; | ||
| 41 | my $nb = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 42 | |||
| 43 | my $name = $self->get_name; | ||
| 44 | my $roc = 0; | ||
| 45 | |||
| 46 | $self->remove_volatile_dependencies(); | ||
| 47 | $self->add_volatile_arg_dependency(2,$nb); | ||
| 48 | |||
| 49 | return if ($calc->indicators->is_available($name, $i)); | ||
| 50 | return if (! $self->check_dependencies($calc, $i)); | ||
| 51 | |||
| 52 | if ( $self->{'args'}->get_arg_values($calc, $i-$nb+1, 2) != 0 ) | ||
| 53 | { | ||
| 54 | $roc = ( ( $self->{'args'}->get_arg_values($calc, $i, 2) - | ||
| 55 | $self->{'args'}->get_arg_values($calc, $i - $nb , 2) ) / | ||
| 56 | $self->{'args'}->get_arg_values($calc, $i - $nb, 2)) * 100; | ||
| 57 | } | ||
| 58 | $calc->indicators->set($name, $i, $roc); | ||
| 59 | } | ||
| 60 |