GeniusTrader/Indicators/RSquare.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 48 CC 3 SCAR 16.7
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.3
1 package Finance::GeniusTrader::Indicators::RSquare;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # standards upgrade and major corrections Copyright 2008 Thomas Weigert
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$
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::Indicators::BPCorrelation;
17 use Finance::GeniusTrader::Prices;
18  
19 @ISA = qw(Finance::GeniusTrader::Indicators);
20 @NAMES = ("RSquare[#1, #2]");
21 @DEFAULT_ARGS = (14, "{I:Prices CLOSE}");
22  
23 =pod
24  
25 =head1 Finance::GeniusTrader::Indicators::RSquare
26  
27 =head2 Overview
28  
29 This function calculates the R-Squared coefficient.
30  
31 =head2 Calculation
32  
33 Pwr(Corr(Cum(1),C,14,0),2)
34
35 =cut
36  
37 sub initialize {
38 my $self = shift;
39  
40 $self->{'correlation'} = Finance::GeniusTrader::Indicators::BPCorrelation->new([
41 $self->{'args'}->get_arg_constant(1),
42 '{I:Generic:Cum 1 }',
43 $self->{'args'}->get_arg_names(2) ]);
44  
45 $self->add_indicator_dependency($self->{'correlation'}, 1);
46 $self->add_prices_dependency(2);
47 }
48  
49 =pod
50  
51 =head2 Finance::GeniusTrader::Indicators::RSquare::calculate($calc, $day)
52  
53 =cut
54  
55 sub calculate {
56 my ($self, $calc, $i) = @_;
57 my $indic = $calc->indicators;
58 my $prices = $calc->prices;
59 my $period = $self->{'args'}->get_arg_constant(1);
60 my $correlation_name = $self->{'correlation'}->get_name;
61 my $name = $self->get_name;
62  
63 return if ($indic->is_available($name, $i));
64 return if (! $self->check_dependencies($calc, $i));
65  
66 my $correlation_value = $indic->get($correlation_name, $i);
67 my $rsquare_value = $correlation_value ** 2;
68
69 $indic->set($name, $i, $rsquare_value);
70 }
71  
72 1;