| 1 | package Finance::GeniusTrader::Indicators::GMEAN; | ||
| 2 | |||
| 3 | # Copyright 2008 Andreas Hartmann | ||
| 4 | # Based on and for GeniusTrader (C) 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 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 | # $Id: GMEAN.pm,v 1.1 2008/04/22 $ | ||
| 9 | |||
| 10 | # Standards-Version: 1.0 | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 14 | |||
| 15 | use Finance::GeniusTrader::Indicators; | ||
| 16 | use Finance::GeniusTrader::Prices; | ||
| 17 | |||
| 18 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 19 | @NAMES = ("GMEAN[#1,#2]"); | ||
| 20 | @DEFAULT_ARGS=("{I:Prices HIGH}", "{I:Prices LOW}"); | ||
| 21 | |||
| 22 | =head1 Finance::GeniusTrader::Indicators::GMEAN | ||
| 23 | |||
| 24 | =head2 Overview | ||
| 25 | |||
| 26 | The geometric mean indicator calculates the geometic mean of each days high and low. | ||
| 27 | While the arithmetic mean has an equal absolute distance to high and low, | ||
| 28 | the geometric mean has an equal relative distance to high and low. | ||
| 29 | |||
| 30 | arithmetic mean: high - mean = mean - low | ||
| 31 | geometric mean: high / gmean = gmean / low | ||
| 32 | |||
| 33 | =head2 Calculation | ||
| 34 | |||
| 35 | gmean = (high * low)^(1/2) | ||
| 36 | |||
| 37 | =head2 Links | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub initialize { | ||
| 42 | my ($self) = @_; | ||
| 43 | $self->add_arg_dependency(1, 1); | ||
| 44 | $self->add_arg_dependency(2, 1); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub calculate { | ||
| 48 | my ($self, $calc, $i) = @_; | ||
| 49 | my $name = $self->get_name; | ||
| 50 | my $prices = $calc->prices; | ||
| 51 | |||
| 52 | return if ($calc->indicators->is_available($name, $i)); | ||
| 53 | return if (! $self->check_dependencies($calc, $i)); | ||
| 54 | |||
| 55 | my $hi = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 56 | my $lo = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 57 | my $gmean = sqrt($hi * $lo); | ||
| 58 | |||
| 59 | $calc->indicators->set($name, $i, $gmean); | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 |