| 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
MC/DC0%0/1
shift() || 3
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | $this->set_sdays(shift || 2); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 2
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | $this->set_pdays(shift || 100); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 100
MC/DC0%0/1
shift() || 100
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | $this->{sRSI} = Math::Business::RSI->new($this->{sdays}) if exists $this->{sRSI}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$this->{'st'} || 0
$this->{'st'}
Truth table100%2/2
A
A= $this->{'st'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1258 | ▶ | if( defined $close_yesterday ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1257 | ▶ | if( $close_yesterday > $close_today ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 628 | ▶ | $streak = $streak >= 0 ? -1 : $streak-1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | } elsif( $close_yesterday < $close_today ) { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 622 | ▶ | $streak = $streak <= 0 ? 1 : $streak+1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
defined $srsi and defined $crsi and @$prar == $pdaysp1
defined $srsi and defined $crsi
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 115700 | ▶ | $p ++ if $prar->[$i] < $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||