| 1 | package Math::Business::SM::Stochastic; | ||||||||||||||||||||||||||||||||
| 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::SMA; | ||||||||||||||||||||||||||||||
|
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 | 1 | ▶ | use constant METHOD_LANE => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use constant METHOD_FAST => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use constant METHOD_SLOW => 2; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use constant METHOD_FULL => 3; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub recommended { my $class = shift; return $class->new(METHOD_LANE,5,3); } | ||||||||||||||||||||||||||||||
|
Subroutine
recommended: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub method_slow { my $class = shift; return $class->new(METHOD_SLOW,$_[0]||14,$_[1]||3); } | ||||||||||||||||||||||||||||||
|
Subroutine
method_slow: called CC=3 SCAR=12.0
Pod
undocumented
Condition50%2/4
$_[0] || 14
$_[1] || 3
MC/DC0%0/1
$_[0] || 14
$_[0]
MC/DC0%0/1
$_[1] || 3
$_[1]
Truth table50%1/2
A
A= $_[0]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub method_fast { my $class = shift; return $class->new(METHOD_FAST,$_[0]||14,$_[1]||3); } | ||||||||||||||||||||||||||||||
|
Subroutine
method_fast: called CC=3 SCAR=12.0
Pod
undocumented
Condition50%2/4
$_[0] || 14
$_[1] || 3
MC/DC0%0/1
$_[0] || 14
$_[0]
MC/DC0%0/1
$_[1] || 3
$_[1]
Truth table50%1/2
A
A= $_[0]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | sub method_full { my $class = shift; return $class->new(METHOD_FULL,$_[0]||14,$_[1]||3,$_[2]||3); } | ||||||||||||||||||||||||||||||
|
Subroutine
method_full: called CC=4 SCAR=15.8
Pod
undocumented
Condition50%3/6
$_[0] || 14
$_[1] || 3
$_[2] || 3
MC/DC0%0/1
$_[0] || 14
$_[0]
MC/DC0%0/1
$_[1] || 3
$_[1]
MC/DC0%0/1
$_[2] || 3
$_[2]
Truth table50%1/2
A
A= $_[0]
Truth table50%1/2
A
A= $_[1]
Truth table50%1/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | my $meth = shift || METHOD_LANE; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | my $kp = shift || 5; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 5
MC/DC0%0/1
shift() || 5
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | my $dp = shift || 3; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 3
MC/DC0%0/1
shift() || 3
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | my $xp = shift || 3; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 3
MC/DC100%1/1
shift() || 3
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 3 | my $this = bless {}, $class; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 3 | $this->set_method( $meth ); | |||||||||||||||||||||||||||||||
| 34 | 3 | $this->set_days( $kp ); | |||||||||||||||||||||||||||||||
| 35 | 3 | $this->set_dperiod( $dp ); | |||||||||||||||||||||||||||||||
| 36 | 3 | $this->set_xperiod( $xp ); | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 3 | return $this; | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | sub set_days { | ||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
set_days: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 43 | 3 | my $arg = shift; | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | croak "days must be a positive non-zero integer" if $arg <= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 3 | $this->{kp} = $arg; | |||||||||||||||||||||||||||||||
| 48 | 3 | $this->set_tag; | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | sub set_dperiod { | ||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
set_dperiod: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 53 | 3 | my $arg = shift; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | croak "days must be a positive non-zero integer" if $arg <= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 3 | $this->{dp} = $arg; | |||||||||||||||||||||||||||||||
| 58 | 3 | $this->set_tag; | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | sub set_xperiod { | ||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
set_xperiod: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 63 | 3 | my $arg = shift; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | croak "days must be a positive non-zero integer" if $arg <= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 3 | $this->{xp} = $arg; | |||||||||||||||||||||||||||||||
| 68 | 3 | $this->set_tag; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | sub set_method { | ||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
set_method: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 73 | 3 | my $meth = shift; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | croak "method not known" unless grep {$meth == $_} (METHOD_LANE, METHOD_FAST, METHOD_SLOW, METHOD_FULL); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 3 | $this->{m} = $meth; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 3 | delete $this->{ksma}; | |||||||||||||||||||||||||||||||
| 80 | 3 | delete $this->{dsma}; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 3 | $this->set_tag; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 3 | return; | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | sub set_tag { | ||||||||||||||||||||||||||||||||
| 88 | 12 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
set_tag: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 12 | ▶ | return if grep { not defined } @$this{qw(kp dp xp)}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | if( $this->{m} == METHOD_FULL ) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 93 | 1 | $this->{tag} = "FullSTO($this->{kp},$this->{dp},$this->{xp})"; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | } elsif( $this->{m} == METHOD_FAST ) { | ||||||||||||||||||||||||||||||||
| 96 | 1 | $this->{tag} = "FSTO($this->{kp},$this->{dp})"; | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | } elsif( $this->{m} == METHOD_SLOW ) { | ||||||||||||||||||||||||||||||||
| 99 | 1 | $this->{tag} = "SSTO($this->{kp},$this->{dp})"; | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||||||
| 102 | 0 | $this->{tag} = "STO($this->{kp},$this->{dp})"; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||
| 107 | 1 | my $method = { | |||||||||||||||||||||||||||||||
| 108 | METHOD_LANE() => \&insert_lane, | ||||||||||||||||||||||||||||||||
| 109 | METHOD_FAST() => \&insert_fast, | ||||||||||||||||||||||||||||||||
| 110 | METHOD_SLOW() => \&insert_slow, | ||||||||||||||||||||||||||||||||
| 111 | METHOD_FULL() => \&insert_full, | ||||||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | sub insert { | ||||||||||||||||||||||||||||||||
| 115 | 90 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 116 | 90 | my $m = $method->{$this->{m}}; | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 90 | return $this->$m( @_ ); | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | # {{{ sub insert_lane | ||||||||||||||||||||||||||||||||
| 123 | 1 | sub insert_lane { | |||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
insert_lane: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $l = ($this->{low_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$this->{"low_hist"} ||= []
MC/DC0%0/1
$this->{"low_hist"} ||= []
$this->{"low_hist"}
Truth table0%0/2
A
A= $this->{"low_hist"}
| |||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $h = ($this->{high_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$this->{"high_hist"} ||= []
MC/DC0%0/1
$this->{"high_hist"} ||= []
$this->{"high_hist"}
Truth table0%0/2
A
A= $this->{"high_hist"}
| |||||||||||||||||||||||||||||||||
| 128 | 0 | my $kp = $this->{kp}; | |||||||||||||||||||||||||||||||
| 129 | 0 | my $dp = $this->{dp}; | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 0 | my ($K, $D); | |||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | while( defined( my $point = shift ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | croak "insert takes three tuple (high, low, close)" unless ref $point eq "ARRAY" and @$point == 3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $point eq "ARRAY" and @$point == 3
MC/DC0%0/2
ref $point eq "ARRAY" and @$point == 3
ref $point eq "ARRAY"
@$point == 3
Truth table0%0/3
A and B
A= ref $point eq "ARRAY"B= @$point == 3
| |||||||||||||||||||||||||||||||||
| 134 | 0 | my ($t_high, $t_low, $t_close) = @$point; | |||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | push @$l, $t_low; shift @$l while @$l > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | push @$h, $t_high; shift @$h while @$h > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if( @$l == $kp ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my $L = $l->[0]; for( 1 .. $#$l ) { $L = $l->[$_] if $l->[$_] < $L }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $H = $h->[0]; for( 1 .. $#$h ) { $H = $h->[$_] if $h->[$_] > $H }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 0 | $K = 100 * ($t_close - $L)/($H-$L); | |||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $L = $l->[-$dp]; for( (-$dp+1) .. -1 ) { $L = $l->[$_] if $l->[$_] < $L }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $H = $h->[-$dp]; for( (-$dp+1) .. -1 ) { $H = $h->[$_] if $h->[$_] > $H }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 0 | $D = 100 * $H / $L; | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | $this->{K} = $K; | |||||||||||||||||||||||||||||||
| 153 | 0 | $this->{D} = $D; | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 0 | return; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | # }}} | ||||||||||||||||||||||||||||||||
| 159 | # {{{ sub insert_fast | ||||||||||||||||||||||||||||||||
| 160 | sub insert_fast { | ||||||||||||||||||||||||||||||||
| 161 | 30 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
insert_fast: called CC=14 SCAR=26.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 30 | ▶ | my $l = ($this->{low_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$this->{"low_hist"} ||= []
MC/DC100%1/1
$this->{"low_hist"} ||= []
$this->{"low_hist"}
Truth table100%2/2
A
A= $this->{"low_hist"}
| |||||||||||||||||||||||||||||||||
| 164 | 30 | ▶ | my $h = ($this->{high_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$this->{"high_hist"} ||= []
MC/DC100%1/1
$this->{"high_hist"} ||= []
$this->{"high_hist"}
Truth table100%2/2
A
A= $this->{"high_hist"}
| |||||||||||||||||||||||||||||||||
| 165 | 30 | my $kp = $this->{kp}; | |||||||||||||||||||||||||||||||
| 166 | 30 | my $dp = $this->{dp}; | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 30 | ▶ | my $dsma = ($this->{dsma} ||= Math::Business::SMA->new($dp)); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->{"dsma"} ||= "Math::Business::SMA"->new($dp)
MC/DC0%0/2
$this->{"dsma"} ||= "Math::Business::SMA"->new($dp)
$this->{"dsma"}
"Math::Business::SMA"->new($dp)
Truth table66%2/3
A ||= B
A= $this->{"dsma"}B= "Math::Business::SMA"->new($dp)
| |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 30 | my ($K, $D); | |||||||||||||||||||||||||||||||
| 171 | 30 | ▶ | while( defined( my $point = shift ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 172 | 30 | ▶ | croak "insert takes three tuple (high, low, close)" unless ref $point eq "ARRAY" and @$point == 3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $point eq "ARRAY" and @$point == 3
MC/DC0%0/2
ref $point eq "ARRAY" and @$point == 3
ref $point eq "ARRAY"
@$point == 3
Truth table33%1/3
A and B
A= ref $point eq "ARRAY"B= @$point == 3
| |||||||||||||||||||||||||||||||||
| 173 | 30 | my ($t_high, $t_low, $t_close) = @$point; | |||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 30 | ▶ | push @$l, $t_low; shift @$l while @$l > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 176 | 30 | ▶ | push @$h, $t_high; shift @$h while @$h > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 30 | ▶ | if( @$l == $kp ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 179 | 17 | ▶ | my $L = $l->[0]; for( 1 .. $#$l ) { $L = $l->[$_] if $l->[$_] < $L }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 180 | 17 | ▶ | my $H = $h->[0]; for( 1 .. $#$h ) { $H = $h->[$_] if $h->[$_] > $H }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 17 | $K = 100 * ($t_close - $L)/($H-$L); | |||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | 17 | $dsma->insert($K); | |||||||||||||||||||||||||||||||
| 185 | 17 | $D = $dsma->query; | |||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | 30 | $this->{K} = $K; | |||||||||||||||||||||||||||||||
| 190 | 30 | $this->{D} = $D; | |||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 30 | return; | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | # }}} | ||||||||||||||||||||||||||||||||
| 196 | # {{{ sub insert_slow | ||||||||||||||||||||||||||||||||
| 197 | sub insert_slow { | ||||||||||||||||||||||||||||||||
| 198 | 30 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
insert_slow: called CC=15 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 30 | ▶ | my $l = ($this->{low_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$this->{"low_hist"} ||= []
MC/DC100%1/1
$this->{"low_hist"} ||= []
$this->{"low_hist"}
Truth table100%2/2
A
A= $this->{"low_hist"}
| |||||||||||||||||||||||||||||||||
| 201 | 30 | ▶ | my $h = ($this->{high_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$this->{"high_hist"} ||= []
MC/DC100%1/1
$this->{"high_hist"} ||= []
$this->{"high_hist"}
Truth table100%2/2
A
A= $this->{"high_hist"}
| |||||||||||||||||||||||||||||||||
| 202 | 30 | my $kp = $this->{kp}; | |||||||||||||||||||||||||||||||
| 203 | 30 | my $dp = $this->{dp}; | |||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 30 | ▶ | my $dsma = ($this->{dsma} ||= Math::Business::SMA->new($dp)); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->{"dsma"} ||= "Math::Business::SMA"->new($dp)
MC/DC0%0/2
$this->{"dsma"} ||= "Math::Business::SMA"->new($dp)
$this->{"dsma"}
"Math::Business::SMA"->new($dp)
Truth table66%2/3
A ||= B
A= $this->{"dsma"}B= "Math::Business::SMA"->new($dp)
| |||||||||||||||||||||||||||||||||
| 206 | 30 | ▶ | my $ksma = ($this->{ksma} ||= Math::Business::SMA->new($dp)); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->{"ksma"} ||= "Math::Business::SMA"->new($dp)
MC/DC0%0/2
$this->{"ksma"} ||= "Math::Business::SMA"->new($dp)
$this->{"ksma"}
"Math::Business::SMA"->new($dp)
Truth table66%2/3
A ||= B
A= $this->{"ksma"}B= "Math::Business::SMA"->new($dp)
| |||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 30 | my ($K, $D); | |||||||||||||||||||||||||||||||
| 209 | 30 | ▶ | while( defined( my $point = shift ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | 30 | ▶ | croak "insert takes three tuple (high, low, close)" unless ref $point eq "ARRAY" and @$point == 3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $point eq "ARRAY" and @$point == 3
MC/DC0%0/2
ref $point eq "ARRAY" and @$point == 3
ref $point eq "ARRAY"
@$point == 3
Truth table33%1/3
A and B
A= ref $point eq "ARRAY"B= @$point == 3
| |||||||||||||||||||||||||||||||||
| 211 | 30 | my ($t_high, $t_low, $t_close) = @$point; | |||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 30 | ▶ | push @$l, $t_low; shift @$l while @$l > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 214 | 30 | ▶ | push @$h, $t_high; shift @$h while @$h > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 30 | ▶ | if( @$l == $kp ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 217 | 17 | ▶ | my $L = $l->[0]; for( 1 .. $#$l ) { $L = $l->[$_] if $l->[$_] < $L }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | 17 | ▶ | my $H = $h->[0]; for( 1 .. $#$h ) { $H = $h->[$_] if $h->[$_] > $H }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | 17 | $ksma->insert( 100 * ($t_close - $L)/($H-$L) ); | |||||||||||||||||||||||||||||||
| 221 | 17 | $K = $ksma->query; | |||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | 17 | $dsma->insert($K); | |||||||||||||||||||||||||||||||
| 224 | 17 | $D = $dsma->query; | |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 30 | $this->{K} = $K; | |||||||||||||||||||||||||||||||
| 229 | 30 | $this->{D} = $D; | |||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 30 | return; | |||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | # }}} | ||||||||||||||||||||||||||||||||
| 235 | # {{{ sub insert_full | ||||||||||||||||||||||||||||||||
| 236 | sub insert_full { | ||||||||||||||||||||||||||||||||
| 237 | 30 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
insert_full: called CC=16 SCAR=28.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | 30 | ▶ | my $l = ($this->{low_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$this->{"low_hist"} ||= []
MC/DC100%1/1
$this->{"low_hist"} ||= []
$this->{"low_hist"}
Truth table100%2/2
A
A= $this->{"low_hist"}
| |||||||||||||||||||||||||||||||||
| 240 | 30 | ▶ | my $h = ($this->{high_hist} ||= []); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$this->{"high_hist"} ||= []
MC/DC100%1/1
$this->{"high_hist"} ||= []
$this->{"high_hist"}
Truth table100%2/2
A
A= $this->{"high_hist"}
| |||||||||||||||||||||||||||||||||
| 241 | 30 | my $kp = $this->{kp}; | |||||||||||||||||||||||||||||||
| 242 | 30 | my $dp = $this->{dp}; | |||||||||||||||||||||||||||||||
| 243 | 30 | ▶ | my $xp = $this->{xp} || $this->{dp}; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$this->{'xp'} || $this->{'dp'}
MC/DC0%0/2
$this->{'xp'} || $this->{'dp'}
$this->{'xp'}
$this->{'dp'}
Truth table33%1/3
A || B
A= $this->{'xp'}B= $this->{'dp'}
| |||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | 30 | ▶ | my $dsma = ($this->{dsma} ||= Math::Business::SMA->new($xp)); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->{"dsma"} ||= "Math::Business::SMA"->new($xp)
MC/DC0%0/2
$this->{"dsma"} ||= "Math::Business::SMA"->new($xp)
$this->{"dsma"}
"Math::Business::SMA"->new($xp)
Truth table66%2/3
A ||= B
A= $this->{"dsma"}B= "Math::Business::SMA"->new($xp)
| |||||||||||||||||||||||||||||||||
| 246 | 30 | ▶ | my $ksma = ($this->{ksma} ||= Math::Business::SMA->new($xp)); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->{"ksma"} ||= "Math::Business::SMA"->new($xp)
MC/DC0%0/2
$this->{"ksma"} ||= "Math::Business::SMA"->new($xp)
$this->{"ksma"}
"Math::Business::SMA"->new($xp)
Truth table66%2/3
A ||= B
A= $this->{"ksma"}B= "Math::Business::SMA"->new($xp)
| |||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 30 | my ($K, $D); | |||||||||||||||||||||||||||||||
| 249 | 30 | ▶ | while( defined( my $point = shift ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | 30 | ▶ | croak "insert takes three tuple (high, low, close)" unless ref $point eq "ARRAY" and @$point == 3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $point eq "ARRAY" and @$point == 3
MC/DC0%0/2
ref $point eq "ARRAY" and @$point == 3
ref $point eq "ARRAY"
@$point == 3
Truth table33%1/3
A and B
A= ref $point eq "ARRAY"B= @$point == 3
| |||||||||||||||||||||||||||||||||
| 251 | 30 | my ($t_high, $t_low, $t_close) = @$point; | |||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | 30 | ▶ | push @$l, $t_low; shift @$l while @$l > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 254 | 30 | ▶ | push @$h, $t_high; shift @$h while @$h > $kp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | 30 | ▶ | if( @$l == $kp ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 257 | 17 | ▶ | my $L = $l->[0]; for( 1 .. $#$l ) { $L = $l->[$_] if $l->[$_] < $L }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 258 | 17 | ▶ | my $H = $h->[0]; for( 1 .. $#$h ) { $H = $h->[$_] if $h->[$_] > $H }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | 17 | $ksma->insert( 100 * ($t_close - $L)/($H-$L) ); | |||||||||||||||||||||||||||||||
| 261 | 17 | $K = $ksma->query; | |||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | 17 | $dsma->insert($K); | |||||||||||||||||||||||||||||||
| 264 | 17 | $D = $dsma->query; | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 30 | $this->{K} = $K; | |||||||||||||||||||||||||||||||
| 269 | 30 | $this->{D} = $D; | |||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 30 | return; | |||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | # }}} | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | sub query { | ||||||||||||||||||||||||||||||||
| 277 | 90 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 90 | return ($this->{D}, $this->{K}); | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | __END__ | ||||||||||||||||||||||||||||||||