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

Re: [system-traders] display_indicator.pl and RSquare



Hi Alex,

> When I run display_indicator.pl on a stock with RSquare as the
> indicator, it compares it to "14."  What does this mean exactly, and how
> do I get it to compare the stock to another stock to tell the
> correlation between the movements of the two stocks?

Just use BPCorrelation (I:BPCorrelation 14 {I:Prices 500340}
{I:Prices GDAXI}). Below you find a patch that makes this indicator
working with the actual version of GT.

> I'd really like to learn GT in-depth, because I want to start
> contributing to it - I know some Perl, and I know some OO, but not
> much in the way of OO in Perl.  I'll meander to the devel list
> eventually, when I figure out how to use GT so I can fiddle with the
> internals.

At the moment there isn't a great difference between using and
developing GT ... if you want to use it efficently you'll have to dig into
the sources... ;)

CU, Olf
--
Visit my world: http://www.olfsworld.de

Patch:
--- GT/Indicators/BPCorrelation.pm	Sun Mar 14 21:27:47 2004
+++ ../GT/Indicators/BPCorrelation.pm	Tue May 18 09:57:57 2004
@@ -1,6 +1,6 @@
 package GT::Indicators::BPCorrelation;

-# Copyright 2000-2002 Raphaël Hertzog, Fabien Fulhaber
+# Copyright 2000-2004 Raphaël Hertzog, Fabien Fulhaber, Oliver Bossert
 # This file is distributed under the terms of the General Public License
 # version 2 or (at your option) any later version.

@@ -10,7 +10,7 @@
 use GT::Indicators;

 @ISA = qw(GT::Indicators);
-
AT
NAMES = ("BPCorrelation[#1]");
+
AT
NAMES = ("BPCorrelation[#1,#2,#3]");

 =head2 GT::Indicators::Correlation

@@ -19,21 +19,6 @@
 if changes in one item will result in changes in the other item.

 =cut
-sub new {
-    my $type = shift;
-    my $class = ref($type) || $type;
-    my ($args, $key, $f1, $f2) = @_;
-    my $self = { 'args' => defined($args) ? $args : [] };
-
-    if (defined($f1)) {
-	$self->{'_f1'} = $f1;
-    }
-    if (defined($f2)) {
-        $self->{'_f2'} = $f2;
-    }
-
-    return manage_object(\
AT
NAMES, $self, $class, $self->{'args'}, $key);
-}

 sub initialize {
     my ($self) = @_;
@@ -46,10 +31,8 @@
 =cut
 sub calculate {
     my ($self, $calc, $i) = @_;
-    my $getvalue1 = $self->{'_f1'};
-    my $getvalue2 = $self->{'_f2'};
     my $name = $self->get_name;
-    my $period = $self->{'args'}[0];
+    my $period = $self->{'args'}->get_arg_values($calc, $i, 1);
     my $average_x = 0;
     my $average_y = 0;
     my $sum_y = 0;
@@ -57,6 +40,10 @@
     my $sum_xy = 0;

     return if ($calc->indicators->is_available($name, $i));
+
+    $self->remove_volatile_dependencies();
+    $self->add_volatile_arg_dependency(2, $period);
+    $self->add_volatile_arg_dependency(2, $period);
     return if (! $self->check_dependencies($calc, $i));
     return if (defined($period) && ($i + 1 < $period));

@@ -66,18 +53,18 @@

     for(my $n = $i - $period + 1; $n <= $i; $n++) {

-	$average_x += &$getvalue1($calc, $n);
-	$average_y += &$getvalue2($calc, $n);
+	$average_x += $self->{'args'}->get_arg_values($calc, $n, 2);
+	$average_y += $self->{'args'}->get_arg_values($calc, $n, 3);
     }

     $average_x /= $period;
     $average_y /= $period;

     for(my $n = $i - $period + 1; $n <= $i; $n++) {
-	$sum_x += (&$getvalue1($calc, $n) - $average_x) ** 2;
-	$sum_y += (&$getvalue2($calc, $n) - $average_y) ** 2;
-	$sum_xy += (&$getvalue1($calc, $n) - $average_x) *
-		   (&$getvalue2($calc, $n) - $average_y);
+	$sum_x += ($self->{'args'}->get_arg_values($calc, $n, 2) - $average_x)
+** 2; 	$sum_y += ($self->{'args'}->get_arg_values($calc, $n, 3) -
+$average_y) ** 2; 	$sum_xy += ($self->{'args'}->get_arg_values($calc, $n,
+2) - $average_x) * 		   ($self->{'args'}->get_arg_values($calc, $n, 3) -
+$average_y);
     }

     # Calculate the Bravais-Pearson Correlation Coefficient