[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GT] SVN Commit r618 - trunk/GT/Indicators



Author: thomas
Date: 2008-04-22 16:42:03 +0200 (Tue, 22 Apr 2008)
New Revision: 618

Added:
   trunk/GT/Indicators/GMEAN.pm
Modified:
   trunk/GT/Indicators/MEAN.pm
Log:
Add I:GMEAN by Andreas Hartmann. Docu fixes to I:MEAN.

Added: trunk/GT/Indicators/GMEAN.pm
===================================================================
--- trunk/GT/Indicators/GMEAN.pm	                        (rev 0)
+++ trunk/GT/Indicators/GMEAN.pm	2008-04-22 14:42:03 UTC (rev 618)
@@ -0,0 +1,60 @@
+package GT::Indicators::GMEAN;
+
+# Copyright 2008 Andreas Hartmann
+# This file is distributed under the terms of the General Public License
+# version 2 or (at your option) any later version.
+
+# Standards-Version: 1.0
+
+use strict;
+use vars qw(@ISA @NAMES @DEFAULT_ARGS);
+
+use GT::Indicators;
+use GT::Prices;
+
+
AT
ISA = qw(GT::Indicators);
+
AT
NAMES = ("GMEAN[#1,#2]");
+
AT
DEFAULT_ARGS=("{I:Prices HIGH}", "{I:Prices LOW}");
+
+=head1 GT::Indicators::GMEAN
+
+=head2 Overview
+
+The geometric mean indicator calculates the geometic mean of each days high and low.
+While the arithmetic mean has an equal absolute distance to high and low,
+the geometric mean has an equal relative distance to high and low.
+
+arithmetic mean: high - mean = mean - low
+geometric mean: high / gmean = gmean / low
+
+=head2 Calculation
+
+gmean = (high * low)^(1/2)
+
+=head2 Links
+
+=cut
+
+sub initialize {
+	my ($self) = @_;
+	$self->add_arg_dependency(1, 1);
+	$self->add_arg_dependency(2, 1);
+}
+
+sub calculate {
+	my ($self, $calc, $i) = @_;
+	my $name = $self->get_name;
+	my $prices = $calc->prices;
+
+	return if ($calc->indicators->is_available($name, $i));
+	return if (! $self->check_dependencies($calc, $i));
+
+	my $hi = $self->{'args'}->get_arg_values($calc, $i, 1);
+	my $lo = $self->{'args'}->get_arg_values($calc, $i, 2);
+	my $gmean = sqrt($hi * $lo);
+
+	$calc->indicators->set($name, $i, $gmean);
+}
+
+1;
+

Modified: trunk/GT/Indicators/MEAN.pm
===================================================================
--- trunk/GT/Indicators/MEAN.pm	2008-04-22 01:13:15 UTC (rev 617)
+++ trunk/GT/Indicators/MEAN.pm	2008-04-22 14:42:03 UTC (rev 618)
@@ -19,7 +19,7 @@
 @NAMES = ("MEAN[#1,#2]");
 @DEFAULT_ARGS=("{I:Prices HIGH}", "{I:Prices LOW}");
 
-=head1 GT::Indicators::WTCL
+=head1 GT::Indicators::MEAN
 
 =head2 Overview
 
@@ -39,9 +39,6 @@
     $self->add_arg_dependency(2, 1);
 }
 
-=head2 GT::Indicators::WTCL::calculate($calc, $day)
-
-=cut
 sub calculate {
     my ($self, $calc, $i) = @_;
     my $name = $self->get_name;