blib/lib/Math/Business/ConnorRSI.pm

filter: Statementstmt 97.5% 81 / 83 Branchbran 77.7% 28 / 36 Conditioncond 78.5% 11 / 14 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 9 totaltotal 83.3% 135 / 162 SCAR 32.4
CC
25
Cov
90%
insert
14.0
new
4.2
reset
3.1
CRAP 25.6
« blib/lib/Math/Business/ParabolicSAR.pm ↑ Summary blib/lib/Math/Business/DMI.pm »
1 package Math::Business::ConnorRSI;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Math::Business::RSI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 1;
10  
11 0 ▶sub tag { (shift)->{tag} }
Subroutine tag: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 0 ▶sub recommended { (shift)->new() }
Subroutine recommended: not called CC=1 SCAR=6.9
Pod undocumented
14  
15 sub new {
16 1 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.2
Pod undocumented
17 1 my $this = bless {}, $class;
18  
19 1 ▶ $this->set_cdays(shift || 3);
Condition50%1/2
shift() || 3
l!l
10
MC/DC0%0/1
shift() || 3
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
20 1 ▶ $this->set_sdays(shift || 2);
Condition50%1/2
shift() || 2
l!l
10
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
21 1 ▶ $this->set_pdays(shift || 100);
Condition50%1/2
shift() || 100
l!l
10
MC/DC0%0/1
shift() || 100
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
22  
23 1 $this->{cRSI} = Math::Business::RSI->new($this->{cdays});
24 1 $this->{sRSI} = Math::Business::RSI->new($this->{sdays});
25  
26 1 return $this;
27 }
28  
29 sub reset {
30 3 ▶ my $this = shift;
Subroutine reset: called CC=3 SCAR=11.2
Pod undocumented
31  
32 3 delete $this->{cy};
33 3 delete $this->{st};
34  
35 3 ▶ $this->{cRSI} = Math::Business::RSI->new($this->{cdays}) if exists $this->{cRSI};
Branch: 1 branch
BranchTrueFalseTotal
if exists $this->{"cRSI"} 0 3 3
36 3 ▶ $this->{sRSI} = Math::Business::RSI->new($this->{sdays}) if exists $this->{sRSI};
Branch: 1 branch
BranchTrueFalseTotal
if exists $this->{"sRSI"} 0 3 3
37 3 $this->{prar} = [];
38 }
39  
40 sub set_cdays {
41 1 ▶ my $this = shift;
Subroutine set_cdays: called CC=3 SCAR=11.2
Pod undocumented
42 1 my $arg = int(shift);
43  
44 1 ▶ croak "days must be a positive non-zero integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 1 1
45  
46 1 $this->{cdays} = $arg;
47 $this->{tag} = "CRSI($this->{cdays},$this->{sdays},$this->{pdays})"
48 1 ▶ unless grep {not defined} @$this{qw(cdays sdays pdays)};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not defined $_;} @$this{"cdays", "sdays", "pdays"} 0 1 1
49  
50 1 $this->reset;
51 }
52  
53 sub set_sdays {
54 1 ▶ my $this = shift;
Subroutine set_sdays: called CC=3 SCAR=11.2
Pod undocumented
55 1 my $arg = int(shift);
56  
57 1 ▶ croak "days must be a positive non-zero integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 1 1
58  
59 1 $this->{sdays} = $arg;
60 $this->{tag} = "CRSI($this->{cdays},$this->{sdays},$this->{pdays})"
61 1 ▶ unless grep {not defined} @$this{qw(cdays sdays pdays)};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not defined $_;} @$this{"cdays", "sdays", "pdays"} 0 1 1
62  
63 1 $this->reset;
64 }
65  
66 sub set_pdays {
67 1 ▶ my $this = shift;
Subroutine set_pdays: called CC=3 SCAR=11.2
Pod undocumented
68 1 my $arg = int(shift);
69  
70 1 ▶ croak "days must be a positive non-zero integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 1 1
71  
72 1 $this->{pdays} = $arg;
73 $this->{tag} = "CRSI($this->{cdays},$this->{sdays},$this->{pdays})"
74 1 ▶ unless grep {not defined} @$this{qw(cdays sdays pdays)};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not defined $_;} @$this{"cdays", "sdays", "pdays"} 1 0 1
75  
76 1 $this->reset;
77 }
78  
79 sub insert {
80 1258 ▶ my $this = shift;
Subroutine insert: called CC=14 SCAR=26.4
Pod undocumented
81 1258 my $close_yesterday = $this->{cy};
82 1258 ▶ my $streak = $this->{st} || 0;
Condition100%2/2
$this->{'st'} || 0
l!l
12499
MC/DC100%1/1
$this->{'st'} || 0
$this->{'st'}
Truth table100%2/2
A
A= $this->{'st'}
Aresult
11
00
83  
84 1258 my $sRSI = $this->{sRSI};
85 1258 my $cRSI = $this->{cRSI};
86 1258 my $prar = $this->{prar};
87 1258 my $pdays = $this->{pdays};
88  
89 # we store 1 extra so we can compare $pdays values
90 1258 my $pdaysp1 = $pdays + 1;
91  
92 1258 ▶ while( defined( my $close_today = shift ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $close_today = shift())) 1258 1258 2516
93 1258 ▶ if( defined $close_yesterday ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $close_yesterday) 1257 1 1258
94 1257 ▶ if( $close_yesterday > $close_today ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($close_yesterday > $close_today) { } 628 629 1257
elsif ($close_yesterday < $close_today) { } 622 7 629
95 628 ▶ $streak = $streak >= 0 ? -1 : $streak-1;
Branch: 1 branch
BranchTrueFalseTotal
$streak >= 0 ? : 342 286 628
96  
97 } elsif( $close_yesterday < $close_today ) {
98 622 ▶ $streak = $streak <= 0 ? 1 : $streak+1;
Branch: 1 branch
BranchTrueFalseTotal
$streak <= 0 ? : 341 281 622
99  
100 } else {
101 7 $streak = 0;
102 }
103  
104 1257 $sRSI->insert($streak);
105  
106 1257 push @$prar, ($close_today - $close_yesterday)/$close_yesterday;
107 1257 ▶ shift @$prar while @$prar > $pdaysp1;
Branch: 1 branch
BranchTrueFalseTotal
@$prar > $pdaysp1 and do { shift @$prar } 1156 1257 2413
108 }
109  
110 1258 $cRSI->insert($close_today);
111  
112 1258 $close_yesterday = $close_today;
113 }
114  
115 1258 $this->{srsi} = my $srsi = $sRSI->query;
116 1258 $this->{crsi} = my $crsi = $cRSI->query;
117  
118 1258 ▶ if( defined $srsi and defined $crsi and @$prar==$pdaysp1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $srsi and defined $crsi and @$prar == $pdaysp1) 1157 101 1258
Condition100%6/6
defined $srsi and defined $crsi and @$prar == $pdaysp1
!ll&&!rl&&r
5961157
defined $srsi and defined $crsi
!ll&&!rl&&r
411253
MC/DC100%3/3
defined $srsi and defined $crsi and @$prar == $pdaysp1
defined $srsi defined $crsi @$prar == $pdaysp1
Truth table100%4/4
A and B and C
A= defined $srsiB= defined $crsiC= @$prar == $pdaysp1
ABCresult
0XX0
10X0
1100
1111
119 1157 my $v = $prar->[-1];
120 1157 my $p = 0;
121 1157 my $i = $#$prar;
122  
123 # we skip the first one, cuz that's $v
124 1157 ▶ while( (--$i) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i >= 0) 115700 1157 116857
125 115700 ▶ $p ++ if $prar->[$i] < $v;
Branch: 1 branch
BranchTrueFalseTotal
if $prar->[$i] < $v 57531 58169 115700
126 }
127  
128 1157 $this->{prank} = my $PR = 100 * ($p/$pdays);
129 1157 $this->{connor} = ( $srsi + $crsi + $PR ) / 3;
130 }
131  
132 1258 $this->{cy} = $close_yesterday;
133 1258 $this->{st} = $streak;
134 }
135  
136 sub query {
137 1258 ▶ my $this = shift;
Subroutine query: called CC=1 SCAR=0.0
Pod undocumented
138  
139 1258 return $this->{connor};
140 }
141  
142 __END__
« blib/lib/Math/Business/ParabolicSAR.pm ↑ Summary blib/lib/Math/Business/DMI.pm »