App/financeta/indicators.pm

filter: Statementstmt 12.1% 100 / 821 Branchbran 17.0% 28 / 164 Conditioncond 8.7% 4 / 46 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 8.4% 14 / 165 Podpod 0.0% 0 / 8 totaltotal 11.8% 146 / 1231 CC 110 SCAR 39.0
CC
110
Cov
13%
calculate_pnl
420.0
execute_ohlcv
88.9
get_params
72.0
CRAP 49.5
« App/financeta/data/gemini.pm ↑ Summary App/financeta/data/yahoo.pm »
1 package App::financeta::indicators;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.16';
7 2 $VERSION = eval $VERSION;
8 2 ▶use App::financeta::mo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use App::financeta::utils qw(dumper log_filter);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Log::Any '$log', filter => \&App::financeta::utils::log_filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use PDL::NiceSlice;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use PDL::Finance::TA;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use JSON::XS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 $PDL::doubleformat = "%0.6lf";
18 2 has debug => 0;
19 2 has plot_engine => 'highcharts';
20 2 has color_idx => 0;
21 2 has colors => [qw(
22 red
23 yellow
24 pink
25 green
26 cyan
27 violet
28 magenta
29 purple
30 brown
31 blue
32 gold
33 goldenrod
34 dark-orange
35 beige
36 salmon
37 dark-magenta
38 dark-green
39 dark-cyan
40 dark-yellow
41 dark-red
42 antiquewhite
43 dark-spring-green
44 royalblue
45 web-green
46 web-blue
47 dark-blue
48 steelblue
49 dark-chartreuse
50 orchid
51 aquamarine
52 turquoise
53 light-red
54 light-green
55 light-blue
56 light-magenta
57 light-cyan
58 light-goldenrod
59 light-pink
60 light-turquoise
61 spring-green
62 forest-green
63 sea-green
64 midnight-blue
65 navy
66 medium-blue
67 skyblue
68 dark-turquoise
69 dark-pink
70 coral
71 light-coral
72 orange-red
73 dark-salmon
74 khaki
75 dark-khaki
76 dark-goldenrod
77 olive
78 orange
79 dark-violet
80 plum
81 dark-plum
82 dark-olivegreen
83 sandybrown
84 light-salmon
85 lemonchiffon
86 bisque
87 honeydew
88 slategrey
89 seagreen
90 chartreuse
91 greenyellow
92 gray
93 light-gray
94 light-grey
95 grey
96 dark-grey
97 dark-gray
98 slategray
99 black
100 )];
101  
102 0 ▶sub next_color {
Subroutine next_color: not called CC=2 SCAR=17.9
Pod undocumented
103 0 my $self = shift;
104 0 my $idx = $self->color_idx; # read
105 0 my $colors = $self->colors;
106 0 ▶ $idx = 0 if $idx >= scalar @$colors; # reset;
Branch: 1 branch
BranchTrueFalseTotal
if $idx >= scalar @$colors 0 0 0
107 0 $log->info("Using Color Index: $idx");
108 0 $self->color_idx($idx + 1); # update
109 0 return $colors->[$idx];
110 }
111  
112 0 ▶sub _plot_gnuplot_general {
Subroutine _plot_gnuplot_general: not called CC=6 SCAR=37.4
113 0 my ($self, $xdata, $output, $scale) = @_;
114 # output is the same as the return value of the code-ref above
115 0 my @plotinfo = ();
116 0 foreach (@$output) {
117 0 ▶ my $p = (defined $scale) ? $_->[1] / $scale : $_->[1];
Branch: 1 branch
BranchTrueFalseTotal
defined $scale ? : 0 0 0
118 0 ▶ my %legend = (legend => $_->[0]) if length $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if length $_->[0] 0 0 0
119 0 ▶ my $args = $_->[2] || {};
Condition0%0/2
$_->[2] || {}
l!l
00
MC/DC0%0/1
$_->[2] || {}
$_->[2]
Truth table0%0/2
A
A= $_->[2]
Aresult
11
00
120 0 $log->debug("Plot args: ", dumper($args));
121 0 push @plotinfo, {
122 with => 'lines',
123 axes => 'x1y1',
124 linecolor => $self->next_color,
125 %legend,
126 %$args,
127 }, $xdata, $p;
128 }
129 0 ▶ return wantarray ? @plotinfo : \@plotinfo;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
130 }
131  
132 0 ▶sub _plot_highcharts_general {
Subroutine _plot_highcharts_general: not called CC=6 SCAR=37.4
133 0 my ($self, $xdata, $output, $scale) = @_;
134 0 my @plotinfo = ();
135 0 foreach my $o (@$output) {
136 ## this is an array
137 #[0] => legend title
138 #[1] => PDL data
139 #[2] => gnuplot args or undef
140 #[3] => variable name for execution rules
141 ## let's create a x-y pdl data
142 ## highcharts requires timestamp in milliseconds;
143 0 ▶ my $xypdl = pdl($xdata * 1000, (defined $scale) ? $o->[1] / $scale : $o->[1])->transpose->setbadtoval(0);
Branch: 1 branch
BranchTrueFalseTotal
defined $scale ? : 0 0 0
144 0 my $xyidx = $xypdl((1))->which;
145 0 my $xypdlclean = $xypdl->dice_axis(1, $xyidx);
146 0 $log->debug($o->[0], $xypdlclean);
147 push @plotinfo, {
148 title => $o->[0],
149 data => encode_json $xypdlclean->unpdl,
150 0 ▶ impulses => (ref $o->[2] eq 'HASH' and $o->[2]->{with} eq 'impulses') ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
ref $o->[2] eq 'HASH' && $o->[2]{'with'} eq 'impulses' ? : 0 0 0
Condition0%0/3
ref $o->[2] eq "HASH" and $o->[2]{"with"} eq "impulses"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $o->[2] eq "HASH" and $o->[2]{"with"} eq "impulses"
ref $o->[2] eq "HASH" $o->[2]{"with"} eq "impulses"
Truth table0%0/3
A and B
A= ref $o->[2] eq "HASH"B= $o->[2]{"with"} eq "impulses"
ABresult
0X0
100
111
151 id => $o->[3],
152 };
153 }
154 0 ▶ return wantarray ? @plotinfo : \@plotinfo;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
155 }
156  
157 0 ▶sub _plot_gnuplot_volume {
Subroutine _plot_gnuplot_volume: not called CC=1 SCAR=6.9
158 0 my ($self, $xdata, $output) = @_;
159 0 my @plotinfo = $self->_plot_gnuplot_general($xdata, $output, 1e6);
160 0 return { volume => \@plotinfo };
161 }
162  
163 0 ▶sub _plot_highcharts_volume {
Subroutine _plot_highcharts_volume: not called CC=1 SCAR=6.9
164 0 my ($self, $xdata, $output) = @_;
165 0 my @plotinfo = $self->_plot_highcharts_general($xdata, $output, 1e6);
166 0 return { volume => \@plotinfo };
167 }
168  
169 0 ▶sub _plot_gnuplot_additional {
Subroutine _plot_gnuplot_additional: not called CC=1 SCAR=6.9
170 0 my ($self, $xdata, $output) = @_;
171 0 my @plotinfo = $self->_plot_gnuplot_general($xdata, $output);
172 0 return { additional => \@plotinfo };
173 }
174  
175 0 ▶sub _plot_highcharts_additional {
Subroutine _plot_highcharts_additional: not called CC=1 SCAR=6.9
176 0 my ($self, $xdata, $output) = @_;
177 0 my @plotinfo = $self->_plot_highcharts_general($xdata, $output);
178 0 return { additional => \@plotinfo };
179 }
180  
181 0 ▶sub _plot_gnuplot_buysell {
Subroutine _plot_gnuplot_buysell: not called CC=5 SCAR=34.0
182 0 my ($self, $xdata, $output) = @_;
183 0 my $ret = { general => undef, additional => undef };
184 0 my @bsg = ();
185 0 my @bsa = ();
186 0 foreach (@$output) {
187 0 ▶ if ($_->[0] =~ /Buy|Sell/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[0] =~ /Buy|Sell/i) { } 0 0 0
188 0 push @bsg, $_;
189 } else {
190 0 push @bsa, $_;
191 }
192 }
193 0 ▶ $ret->{general} = $self->_plot_gnuplot_general($xdata, \@bsg) if @bsg;
Branch: 1 branch
BranchTrueFalseTotal
if @bsg 0 0 0
194 0 ▶ $ret->{additional} = $self->_plot_gnuplot_general($xdata, \@bsa) if @bsa;
Branch: 1 branch
BranchTrueFalseTotal
if @bsa 0 0 0
195 0 return $ret;
196 }
197  
198 0 ▶sub _plot_highcharts_buysell {
Subroutine _plot_highcharts_buysell: not called CC=1 SCAR=6.9
199 ## not required
200 0 return undef;
201 }
202  
203  
204 0 ▶sub _plot_gnuplot_candlestick {
Subroutine _plot_gnuplot_candlestick: not called CC=4 SCAR=30.0
205 0 my ($self, $xdata, $output) = @_;
206 0 my @plotinfo = ();
207 0 foreach (@$output) {
208 0 my $p = $_->[1];
209 0 ▶ my %legend = (legend => $_->[0]) if length $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if length $_->[0] 0 0 0
210 0 ▶ my $args = $_->[2] || {};
Condition0%0/2
$_->[2] || {}
l!l
00
MC/DC0%0/1
$_->[2] || {}
$_->[2]
Truth table0%0/2
A
A= $_->[2]
Aresult
11
00
211 0 $log->debug("Plot args: ", dumper($args));
212 0 push @plotinfo, {
213 with => 'impulses',
214 axes => 'x1y2',
215 linecolor => $self->next_color,
216 %legend,
217 %$args,
218 }, $xdata, $p;
219 }
220 0 return { candle => \@plotinfo };
221 }
222  
223 0 ▶sub _plot_gnuplot_compare {
Subroutine _plot_gnuplot_compare: not called CC=2 SCAR=17.9
224 0 my ($self, $xdata, $output) = @_;
225 0 ▶ if (scalar @$output >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$output >= 2) { } 0 0 0
226 # we don't want to change the output variable itself
227 # otherwise the plots don't stay the same
228 0 my $o2 = [ @$output ]; # make a copy
229 0 my $o1 = pop @$o2;
230 0 my @g = $self->_plot_gnuplot_general($xdata, [$o1]);
231 0 my @a = $self->_plot_gnuplot_general($xdata, $o2);
232 0 return { general => \@g, additional => \@a };
233 } else {
234 0 my @a = $self->_plot_gnuplot_general($xdata, $output);
235 0 return { additional => \@a };
236 }
237 }
238  
239 0 ▶sub _plot_highcharts_candlestick {
Subroutine _plot_highcharts_candlestick: not called CC=2 SCAR=17.9
240 0 my ($self, $xdata, $output) = @_;
241 0 my @plotinfo = ();
242 0 foreach my $o (@$output) {
243 ## this is an array
244 #[0] => legend title
245 #[1] => PDL data
246 #[2] => gnuplot args or undef
247 #[3] => variable name for execution rules
248 ## let's create a x-y pdl data
249 ## highcharts requires timestamp in milliseconds;
250 0 my $xypdl = pdl($xdata * 1000, $o->[1])->transpose->setbadtoval(0);
251 0 my $xyidx = $xypdl((1))->which;
252 0 my $xypdlclean = $xypdl->dice_axis(1, $xyidx);
253 0 $log->debug($o->[0], $xypdlclean);
254 0 push @plotinfo, {
255 title => $o->[0],
256 data => encode_json $xypdlclean->unpdl,
257 impulses => 1,
258 id => $o->[3],
259 };
260 }
261 0 return { candle => \@plotinfo };
262 }
263  
264 0 ▶sub _plot_highcharts_compare {
Subroutine _plot_highcharts_compare: not called CC=2 SCAR=17.9
265 0 my ($self, $xdata, $output) = @_;
266 0 ▶ if (scalar @$output >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$output >= 2) { } 0 0 0
267 # we don't want to change the output variable itself
268 # otherwise the plots don't stay the same
269 0 my $o2 = [ @$output ]; # make a copy
270 0 my $o1 = pop @$o2;
271 0 my @g = $self->_plot_highcharts_general($xdata, [$o1]);
272 0 my @a = $self->_plot_highcharts_general($xdata, $o2);
273 0 return { general => \@g, additional => \@a };
274 } else {
275 0 my @a = $self->_plot_highcharts_general($xdata, $output);
276 0 return { additional => \@a };
277 }
278 }
279  
280 2 has ma_name => {
281 0 => 'SMA',
282 1 => 'EMA',
283 2 => 'WMA',
284 3 => 'DEMA',
285 4 => 'TEMA',
286 5 => 'TRIMA',
287 6 => 'KAMA',
288 7 => 'MAMA',
289 8 => 'T3',
290 };
291  
292 #TODO: verify parameters that are entered by the user
293 has overlaps => {
294 bbands => {
295 name => 'Bollinger Bands',
296 params => [
297 # key, pretty name, type, default value
298 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 5],
299 [ 'InNbDevUp', 'Upper Deviation multiplier', PDL::float, 2.0],
300 [ 'InNbDevDn', 'Lower Deviation multiplier', PDL::float, 2.0],
301 # this will show up in a combo list
302 [ 'InMAType', 'Moving Average Type', 'ARRAY',
303 [
304 'Simple', #SMA
305 'Exponential', #EMA
306 'Weighted', #WMA
307 'Double Exponential', #DEMA
308 'Triple Exponential', #TEMA
309 'Triangular', #TRIMA
310 'Kaufman Adaptive', #KAMA
311 'MESA Adaptive', #MAMA
312 'Triple Exponential (T3)', #T3
313 ],
314 ],
315 ],
316 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
317 0 my ($obj, $inpdl, @args) = @_;
318 0 $log->debug("Executing ta_bbands with parameters: ", dumper(\@args));
319 0 my $period = $args[0];
320 0 my ($upper, $middle, $lower) = PDL::ta_bbands($inpdl, @args);
321 return [
322 0 ["Upper Band($period)", $upper, undef, "bbands_upper_$period"],
323 ["Middle Band($period)", $middle, undef, "bbands_middle_$period"],
324 ["Lower Band($period)", $lower, undef, "bbands_lower_$period"],
325 ];
326 },
327 # use Gnuplot related stuff
328 gnuplot => \&_plot_gnuplot_general,
329 highcharts => \&_plot_highcharts_general,
330 },
331 dema => {
332 name => 'Double Exponential Moving Average',
333 params => [
334 # key, pretty name, type, default value
335 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
336 ],
337 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
338 0 my ($obj, $inpdl, @args) = @_;
339 0 $log->debug("Executing ta_dema with parameters: ", dumper(\@args));
340 0 my $period = $args[0];
341 0 my $outpdl = PDL::ta_dema($inpdl, @args);
342 return [
343 0 ["DEMA($period)", $outpdl, undef, "dema_$period"],
344 ];
345 },
346 gnuplot => \&_plot_gnuplot_general,
347 highcharts => \&_plot_highcharts_general,
348 },
349 ema => {
350 name => 'Exponential Moving Average',
351 params => [
352 # key, pretty name, type, default value
353 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
354 ],
355 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
356 0 my ($obj, $inpdl, @args) = @_;
357 0 $log->debug("Executing ta_ema with parameters: ", dumper(\@args));
358 0 my $period = $args[0];
359 0 my $outpdl = PDL::ta_ema($inpdl, @args);
360 return [
361 0 ["EMA($period)", $outpdl, undef, "ema_$period"],
362 ];
363 },
364 gnuplot => \&_plot_gnuplot_general,
365 highcharts => \&_plot_highcharts_general,
366 },
367 kama => {
368 name => 'Kaufman Adaptive Moving Average',
369 params => [
370 # key, pretty name, type, default value
371 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
372 ],
373 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
374 0 my ($obj, $inpdl, @args) = @_;
375 0 $log->debug("Executing ta_kama with parameters: ", dumper(\@args));
376 0 my $period = $args[0];
377 0 my $outpdl = PDL::ta_kama($inpdl, @args);
378 return [
379 0 ["KAMA($period)", $outpdl, undef, "kama_$period"],
380 ];
381 },
382 gnuplot => \&_plot_gnuplot_general,
383 highcharts => \&_plot_highcharts_general,
384 },
385 ma => {
386 name => 'Moving Average',
387 params => [
388 # key, pretty name, type, default value
389 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
390 # this will show up in a combo list
391 [ 'InMAType', 'Moving Average Type', 'ARRAY',
392 [
393 'Simple', #SMA
394 'Exponential', #EMA
395 'Weighted', #WMA
396 'Double Exponential', #DEMA
397 'Triple Exponential', #TEMA
398 'Triangular', #TRIMA
399 'Kaufman Adaptive', #KAMA
400 'MESA Adaptive', #MAMA
401 'Triple Exponential (T3)', #T3
402 ],
403 ],
404 ],
405 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
406 0 my ($obj, $inpdl, @args) = @_;
407 0 $log->debug("Executing ta_ma with parameters: ", dumper(\@args));
408 0 my $period = $args[0];
409 0 ▶ my $type = $obj->ma_name->{$args[1]} || 'UNKNOWN';
Condition0%0/2
$obj->ma_name->{$args[1]} || 'UNKNOWN'
l!l
00
MC/DC0%0/1
$obj->ma_name->{$args[1]} || 'UNKNOWN'
$obj->ma_name->{$args[1]}
Truth table0%0/2
A
A= $obj->ma_name->{$args[1]}
Aresult
11
00
410 0 my $outpdl = PDL::ta_ma($inpdl, @args);
411 return [
412 0 ["MA($period)($type)", $outpdl, undef, "ma_$type\_$period"],
413 ];
414 },
415 gnuplot => \&_plot_gnuplot_general,
416 highcharts => \&_plot_highcharts_general,
417 },
418 mama => {
419 name => 'MESA Adaptive Moving Average',
420 params => [
421 # key, pretty name, type, default value
422 [ 'InFastLimit', 'Upper Limit (0.01 - 0.99)', PDL::double, 0.5],
423 [ 'InSlowLimit', 'Lower Limit (0.01 - 0.99)', PDL::double, 0.05],
424 ],
425 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
426 0 my ($obj, $inpdl, @args) = @_;
427 0 $log->debug("Executing ta_mama with parameters: ", dumper(\@args));
428 0 my ($omama, $ofama) = PDL::ta_mama($inpdl, @args);
429 return [
430 0 ["MAMA", $omama, undef, "mama"],
431 ["FAMA", $ofama, undef, "fama"],
432 ];
433 },
434 gnuplot => \&_plot_gnuplot_general,
435 highcharts => \&_plot_highcharts_general,
436 },
437 mavp => {
438 name => 'Moving Average with Variable Period',
439 input => [qw/close/],
440 params => [
441 # key, pretty name, type, default value
442 [ 'InPeriods', 'List of periods (comma separated values)', 'PDL', ''],
443 [ 'InMinPeriod', 'Minimum Period (2 - 100000)', PDL::long, 2],
444 [ 'InMaxPeriod', 'Maximum Period (2 - 100000)', PDL::long, 30],
445 # this will show up in a combo list
446 [ 'InMAType', 'Moving Average Type', 'ARRAY',
447 [
448 'Simple', #SMA
449 'Exponential', #EMA
450 'Weighted', #WMA
451 'Double Exponential', #DEMA
452 'Triple Exponential', #TEMA
453 'Triangular', #TRIMA
454 'Kaufman Adaptive', #KAMA
455 'MESA Adaptive', #MAMA
456 'Triple Exponential (T3)', #T3
457 ],
458 ],
459 ],
460 0 ▶ code => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
461 0 my ($obj, $inpdl, $period_pdl, @args) = @_;
462 0 $log->debug("Executing ta_mavp with parameters: ", $period_pdl, "\t", dumper(\@args));
463 0 ▶ my $type = $obj->ma_name->{$args[2]} || 'UNKNOWN';
Condition0%0/2
$obj->ma_name->{$args[2]} || 'UNKNOWN'
l!l
00
MC/DC0%0/1
$obj->ma_name->{$args[2]} || 'UNKNOWN'
$obj->ma_name->{$args[2]}
Truth table0%0/2
A
A= $obj->ma_name->{$args[2]}
Aresult
11
00
464 0 ▶ if ($period_pdl->isnull) {
Branch: 1 branch
BranchTrueFalseTotal
if ($period_pdl->isnull) 0 0 0
465 0 $log->error("The list of periods cannot be null");
466 0 return;
467 }
468 # the period-pdl has to be the same size as the input-pdl
469 0 my $sz = $inpdl->dim(0); #1-D pdl
470 0 my $np = $period_pdl;
471 0 ▶ if ($period_pdl->dim(0) != $sz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($period_pdl->dim(0) != $sz) 0 0 0
472 0 my $rep = POSIX::ceil($inpdl->dim(0) / $period_pdl->dim(0));
473 0 $np = $period_pdl(,*$rep)->clump(0, 1);
474 0 $np = $np->dice([0 .. $sz - 1]);
475 }
476 0 ▶ if ($np->dim(0) != $sz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($np->dim(0) != $sz) 0 0 0
477 0 $log->error("Sizes of the PDLs are not the same: ", $np->dim(0), " vs $sz");
478 0 return;
479 }
480 0 my $outpdl = PDL::ta_mavp($inpdl, $np, @args);
481 return [
482 0 ["MAVP($type)", $outpdl, undef, "mavp_$type"],
483 ];
484 },
485 gnuplot => \&_plot_gnuplot_general,
486 highcharts => \&_plot_highcharts_general,
487 },
488 sar => {
489 name => 'Parabolic Stop And Reverse (SAR)',
490 params => [
491 # key, pretty name, type, default value
492 [ 'InAcceleration', 'Acceleration Factor(>= 0)', PDL::double, 0.02],
493 [ 'InMaximum', 'Max. Acceleration Factor(>= 0)', PDL::double, 0.2],
494 ],
495 input => ['high', 'low'],
496 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
497 0 my ($obj, $highpdl, $lowpdl, @args) = @_;
498 0 $log->debug("Executing ta_sar parameters: ", dumper(\@args));
499 0 my $outpdl = PDL::ta_sar($highpdl, $lowpdl, @args);
500 return [
501 0 ["SAR", $outpdl, {with => 'points pointtype 7'}, "sar"], #bug in P:G:G
502 ];
503 },
504 gnuplot => \&_plot_gnuplot_general,
505 highcharts => \&_plot_highcharts_general,
506 },
507 sarext => {
508 name => 'Parabolic Stop And Reverse (SAR) - Extended',
509 params => [
510 # key, pretty name, type, default value
511 [ 'InStartValue', 'Start Value', PDL::double, 0.0],
512 [ 'InOffsetOnReverse', 'Percent Offset(>= 0)', PDL::double, 0.0],
513 [ 'InAccelerationInitLong', 'Acceleration Factor Initial Long(>= 0)', PDL::double, 0.02],
514 [ 'InAccelerationLong', 'Acceleration Factor Long(>= 0)', PDL::double, 0.02],
515 [ 'InAccelerationMaxLong', 'Acceleration Factor Max. Long(>= 0)', PDL::double, 0.2],
516 [ 'InAccelerationInitShort', 'Acceleration Factor Initial Short(>= 0)', PDL::double, 0.02],
517 [ 'InAccelerationShort', 'Acceleration Factor Short(>= 0)', PDL::double, 0.02],
518 [ 'InAccelerationMaxShort', 'Acceleration Factor Max. Short(>= 0)', PDL::double, 0.2],
519 ],
520 input => ['high', 'low'],
521 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
522 0 my ($obj, $highpdl, $lowpdl, @args) = @_;
523 0 $log->debug("Executing ta_sarext parameters: ", dumper(\@args));
524 0 my $outpdl = PDL::ta_sarext($highpdl, $lowpdl, @args);
525 0 my $shortpdl = $outpdl;
526 0 $shortpdl = $shortpdl->setbadif($shortpdl > 0)->abs;
527 0 $outpdl = $outpdl->setbadif($outpdl < 0);
528 return [
529 0 ["SAR(long)", $outpdl, {with => 'points pointtype 7', linecolor => 'red'}, "sar_long"], # bug in P:G:G
530 ["SAR(short)", $shortpdl, {with => 'points pointtype 7', linecolor => 'green'}, "sar_short"], # bug in P:G:G
531 ];
532 },
533 gnuplot => \&_plot_gnuplot_general,
534 highcharts => \&_plot_highcharts_general,
535 },
536 sma => {
537 name => 'Simple Moving Average',
538 params => [
539 # key, pretty name, type, default value
540 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
541 ],
542 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
543 0 my ($obj, $inpdl, @args) = @_;
544 0 $log->debug("Executing ta_sma with parameters: ", dumper(\@args));
545 0 my $period = $args[0];
546 0 my $outpdl = PDL::ta_sma($inpdl, @args);
547 return [
548 0 ["SMA($period)", $outpdl, undef, "sma_$period"],
549 ];
550 },
551 gnuplot => \&_plot_gnuplot_general,
552 highcharts => \&_plot_highcharts_general,
553 },
554 t3 => {
555 name => 'Triple Exponential Moving Average (T3)',
556 params => [
557 # key, pretty name, type, default value
558 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 5],
559 [ 'InVFactor', 'Volume Factor(0.0 - 1.0)', PDL::double, 0.7],
560 ],
561 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
562 0 my ($obj, $inpdl, @args) = @_;
563 0 $log->debug("Executing ta_t3 with parameters: ", dumper(\@args));
564 0 my $period = $args[0];
565 0 my $outpdl = PDL::ta_t3($inpdl, @args);
566 return [
567 0 ["T3-EMA($period)", $outpdl, undef, "t3ema_$period"],
568 ];
569 },
570 gnuplot => \&_plot_gnuplot_general,
571 highcharts => \&_plot_highcharts_general,
572 },
573 tema => {
574 name => 'Triple Exponential Moving Average',
575 params => [
576 # key, pretty name, type, default value
577 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
578 ],
579 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
580 0 my ($obj, $inpdl, @args) = @_;
581 0 $log->debug("Executing ta_trima with parameters: ", dumper(\@args));
582 0 my $period = $args[0];
583 0 my $outpdl = PDL::ta_tema($inpdl, @args);
584 return [
585 0 ["TEMA($period)", $outpdl, undef, "tema_$period"],
586 ];
587 },
588 gnuplot => \&_plot_gnuplot_general,
589 highcharts => \&_plot_highcharts_general,
590 },
591 trima => {
592 name => 'Triangular Moving Average',
593 params => [
594 # key, pretty name, type, default value
595 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
596 ],
597 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
598 0 my ($obj, $inpdl, @args) = @_;
599 0 $log->debug("Executing ta_trima with parameters: ", dumper(\@args));
600 0 my $period = $args[0];
601 0 my $outpdl = PDL::ta_trima($inpdl, @args);
602 return [
603 0 ["TRIMA($period)", $outpdl, undef, "trima_$period"],
604 ];
605 },
606 gnuplot => \&_plot_gnuplot_general,
607 highcharts => \&_plot_highcharts_general,
608 },
609 wma => {
610 name => 'Weighted Moving Average',
611 params => [
612 # key, pretty name, type, default value
613 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 30],
614 ],
615 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
616 0 my ($obj, $inpdl, @args) = @_;
617 0 $log->debug("Executing ta_wma with parameters: ", dumper(\@args));
618 0 my $period = $args[0];
619 0 my $outpdl = PDL::ta_wma($inpdl, @args);
620 return [
621 0 ["WMA($period)", $outpdl, undef, "wma_$period"],
622 ];
623 },
624 2 gnuplot => \&_plot_gnuplot_general,
625 highcharts => \&_plot_highcharts_general,
626 },
627 ### SKELETON
628 #key => {
629 # name => 'Pretty Name',
630 # params => [
631 # ['key', 'pretty name', 'type', 'default value'],
632 # #...add more if required...
633 # ],
634 # input => [qw/high low/] # default is [/close/]
635 # code => sub {
636 # my ($indicator_obj, $input_pdl, @params) = @_;
637 # #...add code here...
638 # # output array-ref
639 # return [ ['Pretty Name', $output_pdl_1, {plot => 'params'}, "varname"],...];
640 # },
641 # gnuplot => sub {
642 # my ($indicator_obj, $x_axis_pdl, $output_array_ref) = @_;
643 # #...add plotting arguments here in an array
644 # return @plot_args;
645 # },
646 #}
647 };
648  
649 has volatility => {
650 atr => {
651 name => 'Average True Range',
652 params => [
653 # key, pretty name, type, default value
654 [ 'InTimePeriod', 'Period Window (1 - 100000)', PDL::long, 14],
655 ],
656 input => [qw/high low close/],
657 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
658 0 my ($obj, $high, $low, $close, @args) = @_;
659 0 $log->debug("Executing ta_atr with parameters: ", dumper(\@args));
660 0 my $period = $args[0];
661 0 my $outpdl = PDL::ta_atr($high, $low, $close, @args);
662 return [
663 0 ["ATR($period)", $outpdl, undef, "atr_$period"],
664 ];
665 },
666 gnuplot => \&_plot_gnuplot_additional,
667 highcharts => \&_plot_highcharts_additional,
668 },
669 natr => {
670 name => 'Normalized Average True Range',
671 params => [
672 # key, pretty name, type, default value
673 [ 'InTimePeriod', 'Period Window (1 - 100000)', PDL::long, 14],
674 ],
675 input => [qw/high low close/],
676 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
677 0 my ($obj, $high, $low, $close, @args) = @_;
678 0 $log->debug("Executing ta_natr with parameters: ", dumper(\@args));
679 0 my $period = $args[0];
680 0 my $outpdl = PDL::ta_natr($high, $low, $close, @args);
681 return [
682 0 ["NATR($period)", $outpdl, undef, "natr_$period"],
683 ];
684 },
685 gnuplot => \&_plot_gnuplot_additional,
686 highcharts => \&_plot_highcharts_additional,
687 },
688 trange => {
689 name => 'True Range',
690 params => [
691 # no params
692 ],
693 input => [qw/high low close/],
694 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
695 0 my ($obj, $high, $low, $close) = @_;
696 0 $log->debug("Executing ta_trange");
697 0 my $outpdl = PDL::ta_trange($high, $low, $close);
698 return [
699 0 ["True Range", $outpdl, undef, "truerange"],
700 ];
701 },
702 2 gnuplot => \&_plot_gnuplot_additional,
703 highcharts => \&_plot_highcharts_additional,
704 },
705 };
706  
707 has momentum => {
708 adx => {
709 name => 'Average Directional Movement Index (ADX)',
710 params => [
711 # key, pretty name, type, default value
712 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
713 ],
714 input => [qw/high low close/],
715 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
716 0 my ($obj, $high, $low, $close, @args) = @_;
717 0 $log->debug("Executing ta_adx with parameters: ", dumper(\@args));
718 0 my $period = $args[0];
719 0 my $outpdl = PDL::ta_adx($high, $low, $close, @args);
720 return [
721 0 ["ADX($period)", $outpdl, undef, "adx_$period"],
722 ];
723 },
724 gnuplot => \&_plot_gnuplot_additional,
725 highcharts => \&_plot_highcharts_additional,
726 },
727 adxr => {
728 name => 'Average Directional Movement Index Rating (ADXR)',
729 params => [
730 # key, pretty name, type, default value
731 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
732 ],
733 input => [qw/high low close/],
734 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
735 0 my ($obj, $high, $low, $close, @args) = @_;
736 0 $log->debug("Executing ta_adxr with parameters: ", dumper(\@args));
737 0 my $period = $args[0];
738 0 my $outpdl = PDL::ta_adxr($high, $low, $close, @args);
739 return [
740 0 ["ADX RATING($period)", $outpdl, undef, "adx_rating_$period"],
741 ];
742 },
743 gnuplot => \&_plot_gnuplot_additional,
744 highcharts => \&_plot_highcharts_additional,
745 },
746 apo => {
747 name => 'Absolute Price Oscillator (APO)',
748 params => [
749 # key, pretty name, type, default value
750 [ 'InFastPeriod', 'Fast MA Period Window (2 - 100000)', PDL::long, 12],
751 [ 'InSlowPeriod', 'Slow MA Period Window (2 - 100000)', PDL::long, 26],
752 # this will show up in a combo list
753 [ 'InMAType', 'Moving Average Type', 'ARRAY',
754 [
755 'Simple', #SMA
756 'Exponential', #EMA
757 'Weighted', #WMA
758 'Double Exponential', #DEMA
759 'Triple Exponential', #TEMA
760 'Triangular', #TRIMA
761 'Kaufman Adaptive', #KAMA
762 'MESA Adaptive', #MAMA
763 'Triple Exponential (T3)', #T3
764 ],
765 ],
766 ],
767 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
768 0 my ($obj, $inpdl, @args) = @_;
769 0 $log->debug("Executing ta_apo with parameters ", dumper(\@args));
770 0 my $fast = $args[0];
771 0 my $slow = $args[1];
772 0 ▶ my $type = $obj->ma_name->{$args[2]} || 'UNKNOWN';
Condition0%0/2
$obj->ma_name->{$args[2]} || 'UNKNOWN'
l!l
00
MC/DC0%0/1
$obj->ma_name->{$args[2]} || 'UNKNOWN'
$obj->ma_name->{$args[2]}
Truth table0%0/2
A
A= $obj->ma_name->{$args[2]}
Aresult
11
00
773 0 my $outpdl = PDL::ta_apo($inpdl, @args);
774 return [
775 0 ["APO($fast,$slow)($type)", $outpdl, { axes => 'x1y2' }, "apo_$fast\_$slow\_$type"],
776 ];
777 },
778 gnuplot => \&_plot_gnuplot_general,
779 highcharts => \&_plot_highcharts_general,
780 },
781 aroon => {
782 name => 'Aroon',
783 params => [
784 # key, pretty name, type, default value
785 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
786 ],
787 input => [qw/high low/],
788 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
789 0 my ($obj, $high, $low, @args) = @_;
790 0 $log->debug("Executing ta_aroon with parameters: ", dumper(\@args));
791 0 my $period = $args[0];
792 0 my ($adown, $aup) = PDL::ta_aroon($high, $low, @args);
793 return [
794 0 ["AROON($period) DOWN", $adown, undef, "aroon_down_$period"],
795 ["AROON($period) UP", $aup, undef, "aroon_up_$period"],
796 ];
797 },
798 gnuplot => \&_plot_gnuplot_additional,
799 highcharts => \&_plot_highcharts_additional,
800 },
801 aroonosc => {
802 name => 'Aroon Oscillator',
803 params => [
804 # key, pretty name, type, default value
805 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
806 ],
807 input => [qw/high low/],
808 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
809 0 my ($obj, $high, $low, @args) = @_;
810 0 $log->debug("Executing ta_aroonosc with parameters: ", dumper(\@args));
811 0 my $period = $args[0];
812 0 my $outpdl = PDL::ta_aroonosc($high, $low, @args);
813 return [
814 0 ["AROON OSC($period)", $outpdl, undef, "aroon_osc_$period"],
815 ];
816 },
817 gnuplot => \&_plot_gnuplot_additional,
818 highcharts => \&_plot_highcharts_additional,
819 },
820 bop => {
821 name => 'Balance Of Power (BOP)',
822 params => [
823 # no params
824 ],
825 input => [qw/open high low close/],
826 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
827 0 my ($obj, $open, $high, $low, $close) = @_;
828 0 $log->debug("Executing ta_bop");
829 0 my $outpdl = PDL::ta_bop($open, $high, $low, $close);
830 return [
831 0 ["Balance of Power", $outpdl, undef, "balpow"],
832 ];
833 },
834 gnuplot => \&_plot_gnuplot_additional,
835 highcharts => \&_plot_highcharts_additional,
836 },
837 cci => {
838 name => 'Commodity Channel Index (CCI)',
839 params => [
840 # key, pretty name, type, default value
841 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
842 ],
843 input => [qw/high low close/],
844 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
845 0 my ($obj, $high, $low, $close, @args) = @_;
846 0 $log->debug("Executing ta_cci with parameters: ", dumper(\@args));
847 0 my $period = $args[0];
848 0 my $outpdl = PDL::ta_cci($high, $low, $close, @args);
849 return [
850 0 ["CCI($period)", $outpdl, undef, "cci_$period"],
851 ];
852 },
853 gnuplot => \&_plot_gnuplot_additional,
854 highcharts => \&_plot_highcharts_additional,
855 },
856 cmo => {
857 name => 'Chande Momentum Oscillator (CMO)',
858 params => [
859 # key, pretty name, type, default value
860 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
861 ],
862 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
863 0 my ($obj, $inpdl, @args) = @_;
864 0 $log->debug("Executing ta_cmo with parameters: ", dumper(\@args));
865 0 my $period = $args[0];
866 0 my $outpdl = PDL::ta_cmo($inpdl, @args);
867 return [
868 0 ["CMO($period)", $outpdl, undef, "cmo_$period"],
869 ];
870 },
871 gnuplot => \&_plot_gnuplot_additional,
872 highcharts => \&_plot_highcharts_additional,
873 },
874 dx => {
875 name => 'Directional Movement Index (DX)',
876 params => [
877 # key, pretty name, type, default value
878 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
879 ],
880 input => [qw/high low close/],
881 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
882 0 my ($obj, $high, $low, $close, @args) = @_;
883 0 $log->debug("Executing ta_dx with parameters: ", dumper(\@args));
884 0 my $period = $args[0];
885 0 my $outpdl = PDL::ta_dx($high, $low, $close, @args);
886 return [
887 0 ["DX($period)", $outpdl, undef, "dx_$period"],
888 ];
889 },
890 gnuplot => \&_plot_gnuplot_additional,
891 highcharts => \&_plot_highcharts_additional,
892 },
893 macd => {
894 name => 'Moving Average Convergence/Divergence (MACD)',
895 params => [
896 # key, pretty name, type, default value
897 [ 'InFastPeriod', 'Fast MA Period Window (2 - 100000)', PDL::long, 12],
898 [ 'InSlowPeriod', 'Slow MA Period Window (2 - 100000)', PDL::long, 26],
899 [ 'InSignalPeriod', 'Signal Line Smoothing (1 - 100000)', PDL::long, 9],
900 ],
901 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
902 0 my ($obj, $inpdl, @args) = @_;
903 0 $log->debug("Executing ta_macd with parameters ", dumper(\@args));
904 0 my $fast = $args[0];
905 0 my $slow = $args[1];
906 0 my $signal = $args[2];
907 0 my ($omacd, $omacdsig, $omacdhist) = PDL::ta_macd($inpdl, @args);
908 return [
909 0 ["MACD($fast/$slow/$signal)", $omacd, undef, "macd_$fast\_$slow\_$signal"],
910 ["MACD Signal($fast/$slow/$signal)", $omacdsig, undef, "macdsig_$fast\_$slow\_$signal"],
911 ["MACD Histogram($fast/$slow/$signal)", $omacdhist, { with => 'impulses' }, "macdhist_$fast\_$slow\_$signal"],
912 ];
913 },
914 gnuplot => \&_plot_gnuplot_additional,
915 highcharts => \&_plot_highcharts_additional,
916 },
917 macdext => {
918 name => 'MACD with different Mov. Avg',
919 params => [
920 # key, pretty name, type, default value
921 [ 'InFastPeriod', 'Fast MA Period Window (2 - 100000)', PDL::long, 12],
922 # this will show up in a combo list
923 [ 'InFastMAType', 'Fast Moving Average Type', 'ARRAY',
924 [
925 'Simple', #SMA
926 'Exponential', #EMA
927 'Weighted', #WMA
928 'Double Exponential', #DEMA
929 'Triple Exponential', #TEMA
930 'Triangular', #TRIMA
931 'Kaufman Adaptive', #KAMA
932 'MESA Adaptive', #MAMA
933 'Triple Exponential (T3)', #T3
934 ],
935 ],
936 [ 'InSlowPeriod', 'Slow MA Period Window (2 - 100000)', PDL::long, 26],
937 # this will show up in a combo list
938 [ 'InSlowMAType', 'Slow Moving Average Type', 'ARRAY',
939 [
940 'Simple', #SMA
941 'Exponential', #EMA
942 'Weighted', #WMA
943 'Double Exponential', #DEMA
944 'Triple Exponential', #TEMA
945 'Triangular', #TRIMA
946 'Kaufman Adaptive', #KAMA
947 'MESA Adaptive', #MAMA
948 'Triple Exponential (T3)', #T3
949 ],
950 ],
951 [ 'InSignalPeriod', 'Signal Line Smoothing (1 - 100000)', PDL::long, 9],
952 # this will show up in a combo list
953 [ 'InSignalMAType', 'Signal Moving Average Type', 'ARRAY',
954 [
955 'Simple', #SMA
956 'Exponential', #EMA
957 'Weighted', #WMA
958 'Double Exponential', #DEMA
959 'Triple Exponential', #TEMA
960 'Triangular', #TRIMA
961 'Kaufman Adaptive', #KAMA
962 'MESA Adaptive', #MAMA
963 'Triple Exponential (T3)', #T3
964 ],
965 ],
966 ],
967 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
968 0 my ($obj, $inpdl, @args) = @_;
969 0 $log->debug("Executing ta_macdext with parameters ", dumper(\@args));
970 0 my $fast = $args[0];
971 0 my $slow = $args[2];
972 0 my $signal = $args[4];
973 0 my ($omacd, $omacdsig, $omacdhist) = PDL::ta_macdext($inpdl, @args);
974 return [
975 0 ["MACDEXT($fast/$slow/$signal)", $omacd, undef, "macdext_$fast\_$slow\_$signal"],
976 ["MACDEXT Signal($fast/$slow/$signal)", $omacdsig, undef, "macdextsig_$fast\_$slow\_$signal"],
977 ["MACDEXT Histogram($fast/$slow/$signal)", $omacdhist, { with => 'impulses' }, "macdexthist_$fast\_$slow\_$signal"],
978 ];
979 },
980 gnuplot => \&_plot_gnuplot_additional,
981 highcharts => \&_plot_highcharts_additional,
982 },
983 macdfix => {
984 name => 'MACD Fixed to 12/26',
985 params => [
986 # key, pretty name, type, default value
987 [ 'InSignalPeriod', 'Signal Line Smoothing (1 - 100000)', PDL::long, 9],
988 ],
989 1 ▶ code => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
990 1 my ($obj, $inpdl, @args) = @_;
991 1 $log->debug("Executing ta_macdfix with parameters ", dumper(\@args));
992 1 my $signal = $args[0];
993 1 my ($omacd, $omacdsig, $omacdhist) = PDL::ta_macdfix($inpdl, @args);
994 return [
995 1 ["MACD(12/26/$signal)", $omacd, undef, "macd_12_26_$signal"],
996 ["MACD Signal(12/26/$signal)", $omacdsig, undef, "macdsig_12_26_$signal"],
997 ["MACD Histogram(12/26/$signal)", $omacdhist, { with => 'impulses' }, "macdhist_12_26_$signal"],
998 ];
999 },
1000 gnuplot => \&_plot_gnuplot_additional,
1001 highcharts => \&_plot_highcharts_additional,
1002 },
1003 mfi => {
1004 name => 'Money Flow Index (MFI)',
1005 params => [
1006 # key, pretty name, type, default value
1007 [ 'InTimePeriod', 'Period Window(2 - 100000)', PDL::long, 14],
1008 ],
1009 input => [qw/high low close volume/],
1010 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1011 0 my ($obj, $high, $low, $close, $volume, @args) = @_;
1012 0 $log->debug("Executing ta_mfi with parameters ", dumper(\@args));
1013 0 my $period = $args[0];
1014 0 my $outpdl = PDL::ta_mfi($high, $low, $close, $volume, @args);
1015 return [
1016 0 ["MFI($period)", $outpdl, undef, "mfi_$period"],
1017 ];
1018 },
1019 gnuplot => \&_plot_gnuplot_additional,
1020 highcharts => \&_plot_highcharts_additional,
1021 },
1022 minus_di => {
1023 name => 'Minus Directional Indicator (-DI)',
1024 params => [
1025 # key, pretty name, type, default value
1026 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 14],
1027 ],
1028 input => [qw/high low close/],
1029 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1030 0 my ($obj, $high, $low, $close, @args) = @_;
1031 0 $log->debug("Executing ta_minus_di with parameters ", dumper(\@args));
1032 0 my $period = $args[0];
1033 0 my $outpdl = PDL::ta_minus_di($high, $low, $close, @args);
1034 return [
1035 0 ["-DI($period)", $outpdl, undef, "minusdi_$period"],
1036 ];
1037 },
1038 gnuplot => \&_plot_gnuplot_additional,
1039 highcharts => \&_plot_highcharts_additional,
1040 },
1041 minus_dm => {
1042 name => 'Minus Directional Movement (-DM)',
1043 params => [
1044 # key, pretty name, type, default value
1045 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 14],
1046 ],
1047 input => [qw/high low/],
1048 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1049 0 my ($obj, $high, $low, @args) = @_;
1050 0 $log->debug("Executing ta_minus_dm with parameters ", dumper(\@args));
1051 0 my $period = $args[0];
1052 0 my $outpdl = PDL::ta_minus_dm($high, $low, @args);
1053 return [
1054 0 ["-DM($period)", $outpdl, undef, "minusdm_$period"],
1055 ];
1056 },
1057 gnuplot => \&_plot_gnuplot_additional,
1058 highcharts => \&_plot_highcharts_additional,
1059 },
1060 mom => {
1061 name => 'Momentum',
1062 params => [
1063 # key, pretty name, type, default value
1064 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 10],
1065 ],
1066 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1067 0 my ($obj, $inpdl, @args) = @_;
1068 0 $log->debug("Executing ta_mom with parameters ", dumper(\@args));
1069 0 my $period = $args[0];
1070 0 my $outpdl = PDL::ta_mom($inpdl, @args);
1071 return [
1072 0 ["MOM($period)", $outpdl, undef, "mom_$period"],
1073 ];
1074 },
1075 gnuplot => \&_plot_gnuplot_additional,
1076 highcharts => \&_plot_highcharts_additional,
1077 },
1078 plus_di => {
1079 name => 'Plus Directional Indicator (+DI)',
1080 params => [
1081 # key, pretty name, type, default value
1082 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 14],
1083 ],
1084 input => [qw/high low close/],
1085 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1086 0 my ($obj, $high, $low, $close, @args) = @_;
1087 0 $log->debug("Executing ta_plus_di with parameters ", dumper(\@args));
1088 0 my $period = $args[0];
1089 0 my $outpdl = PDL::ta_plus_di($high, $low, $close, @args);
1090 return [
1091 0 ["+DI($period)", $outpdl, undef, "plusdi_$period"],
1092 ];
1093 },
1094 gnuplot => \&_plot_gnuplot_additional,
1095 highcharts => \&_plot_highcharts_additional,
1096 },
1097 plus_dm => {
1098 name => 'Plus Directional Movement (+DM)',
1099 params => [
1100 # key, pretty name, type, default value
1101 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 14],
1102 ],
1103 input => [qw/high low/],
1104 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1105 0 my ($obj, $high, $low, @args) = @_;
1106 0 $log->debug("Executing ta_plus_dm with parameters ", dumper(\@args));
1107 0 my $period = $args[0];
1108 0 my $outpdl = PDL::ta_plus_dm($high, $low, @args);
1109 return [
1110 0 ["+DM($period)", $outpdl, undef, "plusdm_$period"],
1111 ];
1112 },
1113 gnuplot => \&_plot_gnuplot_additional,
1114 highcharts => \&_plot_highcharts_additional,
1115 },
1116 ppo => {
1117 name => 'Percentage Price Oscillator (PPO)',
1118 params => [
1119 # key, pretty name, type, default value
1120 [ 'InFastPeriod', 'Fast MA Period Window (2 - 100000)', PDL::long, 12],
1121 [ 'InSlowPeriod', 'Slow MA Period Window (2 - 100000)', PDL::long, 26],
1122 # this will show up in a combo list
1123 [ 'InMAType', 'Fast Moving Average Type', 'ARRAY',
1124 [
1125 'Simple', #SMA
1126 'Exponential', #EMA
1127 'Weighted', #WMA
1128 'Double Exponential', #DEMA
1129 'Triple Exponential', #TEMA
1130 'Triangular', #TRIMA
1131 'Kaufman Adaptive', #KAMA
1132 'MESA Adaptive', #MAMA
1133 'Triple Exponential (T3)', #T3
1134 ],
1135 ],
1136 ],
1137 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1138 0 my ($obj, $inpdl, @args) = @_;
1139 0 $log->debug("Executing ta_ppo with parameters ", dumper(\@args));
1140 0 my $fast = $args[0];
1141 0 my $slow = $args[1];
1142 0 ▶ my $type = $obj->ma_name->{$args[2]} || 'UNKNOWN';
Condition0%0/2
$obj->ma_name->{$args[2]} || 'UNKNOWN'
l!l
00
MC/DC0%0/1
$obj->ma_name->{$args[2]} || 'UNKNOWN'
$obj->ma_name->{$args[2]}
Truth table0%0/2
A
A= $obj->ma_name->{$args[2]}
Aresult
11
00
1143 0 my $outpdl = PDL::ta_ppo($inpdl, @args);
1144 return [
1145 0 ["PPO($fast/$slow)($type)", $outpdl, undef, "ppo_$fast\_$slow\_$type"],
1146 ];
1147 },
1148 gnuplot => \&_plot_gnuplot_additional,
1149 highcharts => \&_plot_highcharts_additional,
1150 },
1151 roc => {
1152 name => 'Rate of Change (ROC)',
1153 params => [
1154 # key, pretty name, type, default value
1155 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 10],
1156 ],
1157 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1158 0 my ($obj, $inpdl, @args) = @_;
1159 0 $log->debug("Executing ta_roc with parameters ", dumper(\@args));
1160 0 my $period = $args[0];
1161 0 my $outpdl = PDL::ta_roc($inpdl, @args);
1162 return [
1163 0 ["ROC($period)", $outpdl, undef, "roc_$period"],
1164 ];
1165 },
1166 gnuplot => \&_plot_gnuplot_additional,
1167 highcharts => \&_plot_highcharts_additional,
1168 },
1169 rocp => {
1170 name => 'Rate of Change Precentage (ROCP)',
1171 params => [
1172 # key, pretty name, type, default value
1173 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 10],
1174 ],
1175 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1176 0 my ($obj, $inpdl, @args) = @_;
1177 0 $log->debug("Executing ta_rocp with parameters ", dumper(\@args));
1178 0 my $period = $args[0];
1179 0 my $outpdl = PDL::ta_rocp($inpdl, @args);
1180 return [
1181 0 ["ROCP($period)", $outpdl, undef, "rocp_$period"],
1182 ];
1183 },
1184 gnuplot => \&_plot_gnuplot_additional,
1185 highcharts => \&_plot_highcharts_additional,
1186 },
1187 rocr => {
1188 name => 'Rate of Change Ratio (ROCR)',
1189 params => [
1190 # key, pretty name, type, default value
1191 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 10],
1192 ],
1193 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1194 0 my ($obj, $inpdl, @args) = @_;
1195 0 $log->debug("Executing ta_rocr with parameters ", dumper(\@args));
1196 0 my $period = $args[0];
1197 0 my $outpdl = PDL::ta_rocr($inpdl, @args);
1198 return [
1199 0 ["ROCR($period)", $outpdl, undef, "rocr_$period"],
1200 ];
1201 },
1202 gnuplot => \&_plot_gnuplot_additional,
1203 highcharts => \&_plot_highcharts_additional,
1204 },
1205 rocr100 => {
1206 name => 'Rate of Change Ratio x 100 (ROCR100)',
1207 params => [
1208 # key, pretty name, type, default value
1209 [ 'InTimePeriod', 'Period Window(1 - 100000)', PDL::long, 10],
1210 ],
1211 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1212 0 my ($obj, $inpdl, @args) = @_;
1213 0 $log->debug("Executing ta_rocr100 with parameters ", dumper(\@args));
1214 0 my $period = $args[0];
1215 0 my $outpdl = PDL::ta_rocr100($inpdl, @args);
1216 return [
1217 0 ["ROCR*100($period)", $outpdl, undef, "rocr100_$period"],
1218 ];
1219 },
1220 gnuplot => \&_plot_gnuplot_additional,
1221 highcharts => \&_plot_highcharts_additional,
1222 },
1223 rsi => {
1224 name => 'Relative Strength Index (RSI)',
1225 params => [
1226 # key, pretty name, type, default value
1227 [ 'InTimePeriod', 'Period Window(2 - 100000)', PDL::long, 14],
1228 ],
1229 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1230 0 my ($obj, $inpdl, @args) = @_;
1231 0 $log->debug("Executing ta_rsi with parameters ", dumper(\@args));
1232 0 my $period = $args[0];
1233 0 my $outpdl = PDL::ta_rsi($inpdl, @args);
1234 return [
1235 0 ["RSI($period)", $outpdl, undef, "rsi_$period"],
1236 ];
1237 },
1238 gnuplot => \&_plot_gnuplot_additional,
1239 highcharts => \&_plot_highcharts_additional,
1240 },
1241 stoch => {
1242 name => 'Stochastic',
1243 params => [
1244 # key, pretty name, type, default value
1245 [ 'InFastK_Period', 'Fast-K Line Period Window (1 - 100000)', PDL::long, 5],
1246 [ 'InSlowK_Period', 'Slow-K Line Period Window (1 - 100000)', PDL::long, 3],
1247 # this will show up in a combo list
1248 [ 'InSlowK_MAType', 'Slow-K Moving Average Type', 'ARRAY',
1249 [
1250 'Simple', #SMA
1251 'Exponential', #EMA
1252 'Weighted', #WMA
1253 'Double Exponential', #DEMA
1254 'Triple Exponential', #TEMA
1255 'Triangular', #TRIMA
1256 'Kaufman Adaptive', #KAMA
1257 'MESA Adaptive', #MAMA
1258 'Triple Exponential (T3)', #T3
1259 ],
1260 ],
1261 [ 'InSlowD_Period', 'Slow-D Line Period Window (1 - 100000)', PDL::long, 3],
1262 # this will show up in a combo list
1263 [ 'InSlowD_MAType', 'Slow-D Moving Average Type', 'ARRAY',
1264 [
1265 'Simple', #SMA
1266 'Exponential', #EMA
1267 'Weighted', #WMA
1268 'Double Exponential', #DEMA
1269 'Triple Exponential', #TEMA
1270 'Triangular', #TRIMA
1271 'Kaufman Adaptive', #KAMA
1272 'MESA Adaptive', #MAMA
1273 'Triple Exponential (T3)', #T3
1274 ],
1275 ],
1276 ],
1277 input => [qw/high low close/],
1278 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1279 0 my ($obj, $high, $low, $close, @args) = @_;
1280 0 $log->debug("Executing ta_stoch with parameters ", dumper(\@args));
1281 0 my $slowK = $args[1];
1282 0 my $slowD = $args[3];
1283 0 my ($oslowK, $oslowD) = PDL::ta_stoch($high, $low, $close, @args);
1284 return [
1285 0 ["Slow-K($slowK)", $oslowK, undef, "slowK_$slowK"],
1286 ["Slow-D($slowD)", $oslowD, undef, "slowD_$slowD"],
1287 ];
1288 },
1289 gnuplot => \&_plot_gnuplot_additional,
1290 highcharts => \&_plot_highcharts_additional,
1291 },
1292 stochf => {
1293 name => 'Stochastic Fast',
1294 params => [
1295 # key, pretty name, type, default value
1296 [ 'InFastK_Period', 'Fast-K Line Period Window (1 - 100000)', PDL::long, 5],
1297 [ 'InFastD_Period', 'Fast-D Line Period Window (1 - 100000)', PDL::long, 3],
1298 # this will show up in a combo list
1299 [ 'InFastD_MAType', 'Fast-D Moving Average Type', 'ARRAY',
1300 [
1301 'Simple', #SMA
1302 'Exponential', #EMA
1303 'Weighted', #WMA
1304 'Double Exponential', #DEMA
1305 'Triple Exponential', #TEMA
1306 'Triangular', #TRIMA
1307 'Kaufman Adaptive', #KAMA
1308 'MESA Adaptive', #MAMA
1309 'Triple Exponential (T3)', #T3
1310 ],
1311 ],
1312 ],
1313 input => [qw/high low close/],
1314 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1315 0 my ($obj, $high, $low, $close, @args) = @_;
1316 0 $log->debug("Executing ta_stochf with parameters ", dumper(\@args));
1317 0 my $fastK = $args[0];
1318 0 my $fastD = $args[1];
1319 0 my ($ofastK, $ofastD) = PDL::ta_stochf($high, $low, $close, @args);
1320 return [
1321 0 ["Fast-K($fastK)", $ofastK, undef, "fastK_$fastK"],
1322 ["Fast-D($fastD)", $ofastD, undef, "fastD_$fastD"],
1323 ];
1324 },
1325 gnuplot => \&_plot_gnuplot_additional,
1326 highcharts => \&_plot_highcharts_additional,
1327 },
1328 stochrsi => {
1329 name => 'Stochastic Relative Strength Index (STOCHRSI)',
1330 params => [
1331 # key, pretty name, type, default value
1332 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
1333 [ 'InFastK_Period', 'Fast-K Line Period Window (1 - 100000)', PDL::long, 5],
1334 [ 'InFastD_Period', 'Fast-D Line Period Window (1 - 100000)', PDL::long, 3],
1335 # this will show up in a combo list
1336 [ 'InFastD_MAType', 'Fast-D Moving Average Type', 'ARRAY',
1337 [
1338 'Simple', #SMA
1339 'Exponential', #EMA
1340 'Weighted', #WMA
1341 'Double Exponential', #DEMA
1342 'Triple Exponential', #TEMA
1343 'Triangular', #TRIMA
1344 'Kaufman Adaptive', #KAMA
1345 'MESA Adaptive', #MAMA
1346 'Triple Exponential (T3)', #T3
1347 ],
1348 ],
1349 ],
1350 input => [qw/close/],
1351 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1352 0 my ($obj, $close, @args) = @_;
1353 0 $log->debug("Executing ta_stochrsi with parameters ", dumper(\@args));
1354 0 my $period = $args[0];
1355 0 my $fastK = $args[1];
1356 0 my $fastD = $args[2];
1357 0 my ($ofastK, $ofastD) = PDL::ta_stochrsi($close, @args);
1358 return [
1359 0 ["Fast-K($fastK, $period)", $ofastK, undef, "fastK_$fastK\_$period"],
1360 ["Fast-D($fastD, $period)", $ofastD, undef, "fastD_$fastD\_$period"],
1361 ];
1362 },
1363 gnuplot => \&_plot_gnuplot_additional,
1364 highcharts => \&_plot_highcharts_additional,
1365 },
1366 trix => {
1367 name => 'ROC of Triple Smooth EMA (TRIX)',
1368 params => [
1369 # key, pretty name, type, default value
1370 [ 'InTimePeriod', 'Period Window (1 - 100000)', PDL::long, 30],
1371 ],
1372 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1373 0 my ($obj, $inpdl, @args) = @_;
1374 0 $log->debug("Executing ta_trix with parameters", dumper(\@args));
1375 0 my $period = $args[0];
1376 0 my $outpdl = PDL::ta_trix($inpdl, @args);
1377 return [
1378 0 ["TRIX($period)", $outpdl, undef, "trix_$period"],
1379 ];
1380 },
1381 gnuplot => \&_plot_gnuplot_additional,
1382 highcharts => \&_plot_highcharts_additional,
1383 },
1384 ultosc => {
1385 name => 'Ultimate Oscillator',
1386 params => [
1387 # key, pretty name, type, default value
1388 [ 'InTimePeriod1', 'Period Window (1 - 100000)', PDL::long, 7],
1389 [ 'InTimePeriod2', 'Period Window (1 - 100000)', PDL::long, 14],
1390 [ 'InTimePeriod3', 'Period Window (1 - 100000)', PDL::long, 28],
1391 ],
1392 input => [qw/high low close/],
1393 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1394 0 my ($obj, $high, $low, $close, @args) = @_;
1395 0 $log->debug("Executing ta_ultosc with parameters ", dumper(\@args));
1396 0 my $p1 = $args[0];
1397 0 my $p2 = $args[1];
1398 0 my $p3 = $args[2];
1399 0 my $outpdl = PDL::ta_ultosc($high, $low, $close, @args);
1400 return [
1401 0 ["ULT.OSC.($p1/$p2/$p3)", $outpdl, undef, "ultosc_$p1\_$p2\_$p3"],
1402 ];
1403 },
1404 gnuplot => \&_plot_gnuplot_additional,
1405 highcharts => \&_plot_highcharts_additional,
1406 },
1407 willr => {
1408 name => q/Williams' %R/,
1409 params => [
1410 # key, pretty name, type, default value
1411 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
1412 ],
1413 input => [qw/high low close/],
1414 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1415 0 my ($obj, $high, $low, $close, @args) = @_;
1416 0 $log->debug("Executing ta_willr with parameters ", dumper(\@args));
1417 0 my $period = $args[0];
1418 0 my $outpdl = PDL::ta_willr($high, $low, $close, @args);
1419 return [
1420 0 ["WILLR($period)", $outpdl, undef, "willr_$period"],
1421 ];
1422 },
1423 2 gnuplot => \&_plot_gnuplot_additional,
1424 highcharts => \&_plot_highcharts_additional,
1425 },
1426 };
1427  
1428 has hilbert => {
1429 ht_trendline => {
1430 name => 'Hilbert Transform - Instantaneous Trendline',
1431 params => [
1432 # no params
1433 ],
1434 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1435 0 my ($obj, $inpdl) = @_;
1436 0 $log->debug("Executing ta_ht_trendline");
1437 0 my $outpdl = PDL::ta_ht_trendline($inpdl);
1438 return [
1439 0 ['HT-trendline', $outpdl, undef, "ht_trend"],
1440 ];
1441 },
1442 gnuplot => \&_plot_gnuplot_general,
1443 highcharts => \&_plot_highcharts_general,
1444 },
1445 ht_dcperiod => {
1446 name => 'Hilbert Transform - Dominant Cycle Period',
1447 params => [
1448 #no params,
1449 ],
1450 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1451 0 my ($obj, $inpdl) = @_;
1452 0 $log->debug("Executing ta_ht_dcperiod");
1453 0 my $outpdl = PDL::ta_ht_dcperiod($inpdl);
1454 return [
1455 0 ['HT-DCperiod', $outpdl, { axes => 'x1y2' }, "ht_dcperiod"],
1456 ];
1457 },
1458 gnuplot => \&_plot_gnuplot_general,
1459 highcharts => \&_plot_highcharts_general,
1460 },
1461 ht_dcphase => {
1462 name => 'Hilbert Transform - Dominant Cycle Phase',
1463 params => [
1464 #no params,
1465 ],
1466 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1467 0 my ($obj, $inpdl) = @_;
1468 0 $log->debug("Executing ta_ht_dcphase");
1469 0 my $outpdl = PDL::ta_ht_dcphase($inpdl);
1470 return [
1471 0 ['HT-DCphase', $outpdl, undef, "ht_dcphase"],
1472 ];
1473 },
1474 gnuplot => \&_plot_gnuplot_additional,
1475 highcharts => \&_plot_highcharts_additional,
1476 },
1477 ht_phasor => {
1478 name => 'Hilbert Transform - In-Phase & Quadrature',
1479 params => [
1480 #no params,
1481 ],
1482 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1483 0 my ($obj, $inpdl) = @_;
1484 0 $log->debug("Executing ta_ht_phasor");
1485 0 my ($oinphase, $oquad) = PDL::ta_ht_phasor($inpdl);
1486 return [
1487 0 ['HT-InPhase', $oinphase, undef, "ht_inphase"],
1488 ['HT-Quadrature', $oquad, undef, "ht_quad"],
1489 ];
1490 },
1491 gnuplot => \&_plot_gnuplot_additional,
1492 highcharts => \&_plot_highcharts_additional,
1493 },
1494 ht_sine => {
1495 name => 'Hilbert Transform - Sine Wave',
1496 params => [
1497 #no params,
1498 ],
1499 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1500 0 my ($obj, $inpdl) = @_;
1501 0 $log->debug("Executing ta_ht_sine");
1502 0 my ($osine, $oleadsine) = PDL::ta_ht_sine($inpdl);
1503 return [
1504 0 ['HT-Sine', $osine, { axes => 'x1y2' }, "ht_sine"],
1505 ['HT-LeadSine', $oleadsine, { axes => 'x1y2' }, "ht_leadsine"],
1506 ];
1507 },
1508 gnuplot => \&_plot_gnuplot_additional,
1509 highcharts => \&_plot_highcharts_additional,
1510 },
1511 ht_trendmode => {
1512 name => 'Hilbert Transform - Market Mode (Trend vs Cycle)',
1513 params => [
1514 #no params,
1515 ],
1516 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1517 0 my ($obj, $inpdl) = @_;
1518 0 $log->debug("Executing ta_ht_trendmode");
1519 0 my $outpdl = PDL::ta_ht_trendmode($inpdl);
1520 return [
1521 0 ['HT-TrendvCycle', $outpdl, { with => 'impulses', axes => 'x1y2' }, "ht_trendcycle"],
1522 ];
1523 },
1524 2 gnuplot => \&_plot_gnuplot_additional,
1525 highcharts => \&_plot_highcharts_additional,
1526 },
1527 };
1528  
1529 has volume => {
1530 ad => {
1531 name => 'Accumulation/Distribution line (A/D)',
1532 params => [
1533 # no params
1534 ],
1535 input => [qw/high low close volume/],
1536 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1537 0 my ($obj, $high, $low, $close, $volume) = @_;
1538 0 $log->debug("Executing ta_ad");
1539 0 my $outpdl = PDL::ta_ad($high, $low, $close, $volume);
1540 return [
1541 0 ["A/D", $outpdl, undef, "chaikin"],
1542 ];
1543 },
1544 gnuplot => \&_plot_gnuplot_volume,
1545 highcharts => \&_plot_highcharts_volume,
1546 },
1547 adosc => {
1548 name => 'Chaikin Accumulation/Distribution Oscillator',
1549 params => [
1550 # key, pretty name, type, default value
1551 [ 'InFastPeriod', 'Fast MA Period Window (2 - 100000)', PDL::long, 3],
1552 [ 'InSlowPeriod', 'Slow MA Period Window (2 - 100000)', PDL::long, 10],
1553 ],
1554 input => [qw/high low close volume/],
1555 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1556 0 my ($obj, $high, $low, $close, $volume, @args) = @_;
1557 0 $log->debug("Executing ta_adosc with parameters ", dumper(\@args));
1558 0 my $fast = $args[0];
1559 0 my $slow = $args[1];
1560 0 my $outpdl = PDL::ta_adosc($high, $low, $close, $volume, @args);
1561 return [
1562 0 ["Chaikin A/D($fast,$slow)", $outpdl, undef, "chaikin_$fast\_$slow"],
1563 ];
1564 },
1565 gnuplot => \&_plot_gnuplot_volume,
1566 highcharts => \&_plot_highcharts_volume,
1567 },
1568 obv => {
1569 name => 'On Balance Volume (OBV)',
1570 params => [
1571 # no params
1572 ],
1573 input => [qw/close volume/],
1574 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1575 0 my ($obj, $close, $volume) = @_;
1576 0 $log->debug("Executing ta_obv");
1577 0 my $outpdl = PDL::ta_obv($close, $volume);
1578 return [
1579 0 ["OBV", $outpdl, undef, "obv"],
1580 ];
1581 },
1582 2 gnuplot => \&_plot_gnuplot_volume,
1583 highcharts => \&_plot_highcharts_volume,
1584 },
1585 };
1586  
1587 0 ▶sub _execute_candlestick {
Subroutine _execute_candlestick: not called CC=3 SCAR=24.8
1588 0 my ($obj, $fn, $fname, $tag, $o, $h, $l, $c, @args) = @_;
1589 0 ▶ return unless ref $fn eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fn eq "CODE" 0 0 0
1590 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 0 0 0
1591 0 $log->debug("Executing $fname with parameters ", dumper(\@args));
1592 } else {
1593 0 $log->debug("Executing $fname");
1594 }
1595 0 my $outpdl = &$fn($o, $h, $l, $c, @args);
1596 0 my $varname = $fname;
1597 0 $varname =~ s/^ta_//g;
1598 return [
1599 0 [$tag, $outpdl, undef, $varname],
1600 ];
1601 }
1602  
1603 has candlestick => {
1604 cdl2crows => {
1605 name => 'Two Crows',
1606 params => [],
1607 input => [qw(open high low close)],
1608 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl2crows, 'ta_cdl2crows', '2CROWS', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1609 gnuplot => \&_plot_gnuplot_candlestick,
1610 highcharts => \&_plot_highcharts_candlestick,
1611 },
1612 cdl3blackcrows => {
1613 name => 'Three Black Crows',
1614 params => [],
1615 input => [qw(open high low close)],
1616 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl3blackcrows, 'ta_cdl3blackcrows', '3BLACKCROWS', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1617 gnuplot => \&_plot_gnuplot_candlestick,
1618 highcharts => \&_plot_highcharts_candlestick,
1619 },
1620 cdl3inside => {
1621 name => 'Three Inside Up/Down',
1622 params => [],
1623 input => [qw(open high low close)],
1624 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl3inside, 'ta_cdl3inside', '3INSIDE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1625 gnuplot => \&_plot_gnuplot_candlestick,
1626 highcharts => \&_plot_highcharts_candlestick,
1627 },
1628 cdl3linestrike => {
1629 name => 'Three Line Strike',
1630 params => [],
1631 input => [qw(open high low close)],
1632 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl3linestrike, 'ta_cdl3linestrike', '3LINESTRIKE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1633 gnuplot => \&_plot_gnuplot_candlestick,
1634 highcharts => \&_plot_highcharts_candlestick,
1635 },
1636 cdl3outside => {
1637 name => 'Three Outside Up/Down',
1638 params => [],
1639 input => [qw(open high low close)],
1640 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl3outside, 'ta_cdl3outside', '3OUTSIDE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1641 gnuplot => \&_plot_gnuplot_candlestick,
1642 highcharts => \&_plot_highcharts_candlestick,
1643 },
1644 cdl3starsinsouth => {
1645 name => 'Three Stars In The South',
1646 params => [],
1647 input => [qw(open high low close)],
1648 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl3starsinsouth, 'ta_cdl3starsinsouth', '3STARSSOUTH', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1649 gnuplot => \&_plot_gnuplot_candlestick,
1650 highcharts => \&_plot_highcharts_candlestick,
1651 },
1652 cdl3whitesoldiers => {
1653 name => 'Three Advancing White Soldiers',
1654 params => [],
1655 input => [qw(open high low close)],
1656 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdl3whitesoldiers, 'ta_cdl3whitesoldiers', '3WHITESOLDIER', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1657 gnuplot => \&_plot_gnuplot_candlestick,
1658 highcharts => \&_plot_highcharts_candlestick,
1659 },
1660 cdlabandonedbaby => {
1661 name => 'Abandoned Baby',
1662 input => [qw(open high low close)],
1663 params => [
1664 # key, pretty name, type, default value
1665 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.3],
1666 ],
1667 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlabandonedbaby, 'ta_cdlabandonedbaby', 'ABANDONBABY', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1668 gnuplot => \&_plot_gnuplot_candlestick,
1669 highcharts => \&_plot_highcharts_candlestick,
1670 },
1671 cdladvanceblock => {
1672 name => 'Advance Block',
1673 params => [],
1674 input => [qw(open high low close)],
1675 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdladvanceblock, 'ta_cdladvanceblock', 'ADVANCEBLK', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1676 gnuplot => \&_plot_gnuplot_candlestick,
1677 highcharts => \&_plot_highcharts_candlestick,
1678 },
1679 cdlbelthold => {
1680 name => 'Belt Hold',
1681 params => [],
1682 input => [qw(open high low close)],
1683 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlbelthold, 'ta_cdlbelthold', 'BELTHOLD', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1684 gnuplot => \&_plot_gnuplot_candlestick,
1685 highcharts => \&_plot_highcharts_candlestick,
1686 },
1687 cdlbreakaway => {
1688 name => 'Break Away',
1689 params => [],
1690 input => [qw(open high low close)],
1691 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlbreakaway, 'ta_cdlbreakaway', 'BREAKAWAY', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1692 gnuplot => \&_plot_gnuplot_candlestick,
1693 highcharts => \&_plot_highcharts_candlestick,
1694 },
1695 cdlclosingmarubozu => {
1696 name => 'Closing Marubozu',
1697 params => [],
1698 input => [qw(open high low close)],
1699 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlclosingmarubozu, 'ta_cdlclosingmarubozu', 'CLOSEMARUBOZU', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1700 gnuplot => \&_plot_gnuplot_candlestick,
1701 highcharts => \&_plot_highcharts_candlestick,
1702 },
1703 cdlconcealbabyswall => {
1704 name => 'Concealing Baby Swallow',
1705 params => [],
1706 input => [qw(open high low close)],
1707 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlconcealbabyswall, 'ta_cdlconcealbabyswall', 'BABYSWALLOW', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1708 gnuplot => \&_plot_gnuplot_candlestick,
1709 highcharts => \&_plot_highcharts_candlestick,
1710 },
1711 cdlcounterattack => {
1712 name => 'Counter Attack',
1713 params => [],
1714 input => [qw(open high low close)],
1715 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlcounterattack, 'ta_cdlcounterattack', 'CTRATTACK', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1716 gnuplot => \&_plot_gnuplot_candlestick,
1717 highcharts => \&_plot_highcharts_candlestick,
1718 },
1719 cdldarkcloudcover => {
1720 name => 'Dark Cloud Cover',
1721 input => [qw(open high low close)],
1722 params => [
1723 # key, pretty name, type, default value
1724 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.5],
1725 ],
1726 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdldarkcloudcover, 'ta_cdldarkcloudcover', 'DARKCLOUD', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1727 gnuplot => \&_plot_gnuplot_candlestick,
1728 highcharts => \&_plot_highcharts_candlestick,
1729 },
1730 cdldoji => {
1731 name => 'Doji',
1732 params => [],
1733 input => [qw(open high low close)],
1734 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdldoji, 'ta_cdldoji', 'DOJI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1735 gnuplot => \&_plot_gnuplot_candlestick,
1736 highcharts => \&_plot_highcharts_candlestick,
1737 },
1738 cdldojistar => {
1739 name => 'Doji Star',
1740 params => [],
1741 input => [qw(open high low close)],
1742 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdldojistar, 'ta_cdldojistar', 'DOJISTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1743 gnuplot => \&_plot_gnuplot_candlestick,
1744 highcharts => \&_plot_highcharts_candlestick,
1745 },
1746 cdldragonflydoji => {
1747 name => 'Dragonfly Doji',
1748 params => [],
1749 input => [qw(open high low close)],
1750 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdldragonflydoji, 'ta_cdldragonflydoji', 'DRGNFLYDOJI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1751 gnuplot => \&_plot_gnuplot_candlestick,
1752 highcharts => \&_plot_highcharts_candlestick,
1753 },
1754 cdlengulfing => {
1755 name => 'Engulfing Pattern',
1756 params => [],
1757 input => [qw(open high low close)],
1758 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlengulfing, 'ta_cdlengulfing', 'ENGULFING', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1759 gnuplot => \&_plot_gnuplot_candlestick,
1760 highcharts => \&_plot_highcharts_candlestick,
1761 },
1762 cdleveningdojistar => {
1763 name => 'Evening Doji Star',
1764 input => [qw(open high low close)],
1765 params => [
1766 # key, pretty name, type, default value
1767 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.3],
1768 ],
1769 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdleveningdojistar, 'ta_cdleveningdojistar', 'EVEDOJISTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1770 gnuplot => \&_plot_gnuplot_candlestick,
1771 highcharts => \&_plot_highcharts_candlestick,
1772 },
1773 cdleveningstar => {
1774 name => 'Evening Star',
1775 input => [qw(open high low close)],
1776 params => [
1777 # key, pretty name, type, default value
1778 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.3],
1779 ],
1780 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdleveningstar, 'ta_cdleveningstar', 'EVESTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1781 gnuplot => \&_plot_gnuplot_candlestick,
1782 highcharts => \&_plot_highcharts_candlestick,
1783 },
1784 cdlgapsidesidewhite => {
1785 name => 'Up/Down Gap Side-by-Side White Lines',
1786 params => [],
1787 input => [qw(open high low close)],
1788 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlgapsidesidewhite, 'ta_cdlgapsidesidewhite', 'GAPSxSWHITE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1789 gnuplot => \&_plot_gnuplot_candlestick,
1790 highcharts => \&_plot_highcharts_candlestick,
1791 },
1792 cdlgravestonedoji => {
1793 name => 'Gravestone Doji',
1794 params => [],
1795 input => [qw(open high low close)],
1796 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlgravestonedoji, 'ta_cdlgravestonedoji', 'GRVSTNDOJI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1797 gnuplot => \&_plot_gnuplot_candlestick,
1798 highcharts => \&_plot_highcharts_candlestick,
1799 },
1800 cdlhammer => {
1801 name => 'Hammer',
1802 params => [],
1803 input => [qw(open high low close)],
1804 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlhammer, 'ta_cdlhammer', 'HAMMER', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1805 gnuplot => \&_plot_gnuplot_candlestick,
1806 highcharts => \&_plot_highcharts_candlestick,
1807 },
1808 cdlhangingman => {
1809 name => 'Hanging Man',
1810 params => [],
1811 input => [qw(open high low close)],
1812 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlhangingman, 'ta_cdlhangingman', 'HANGMAN', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1813 gnuplot => \&_plot_gnuplot_candlestick,
1814 highcharts => \&_plot_highcharts_candlestick,
1815 },
1816 cdlharami => {
1817 name => 'Harami Pattern',
1818 params => [],
1819 input => [qw(open high low close)],
1820 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlharami, 'ta_cdlharami', 'HARAMI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1821 gnuplot => \&_plot_gnuplot_candlestick,
1822 highcharts => \&_plot_highcharts_candlestick,
1823 },
1824 cdlharamicross => {
1825 name => 'Harami Cross Pattern',
1826 params => [],
1827 input => [qw(open high low close)],
1828 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlharamicross, 'ta_cdlharamicross', 'HARAMI-X',@_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1829 gnuplot => \&_plot_gnuplot_candlestick,
1830 highcharts => \&_plot_highcharts_candlestick,
1831 },
1832 cdlhighwave => {
1833 name => 'High-Wave Candle',
1834 params => [],
1835 input => [qw(open high low close)],
1836 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlhighwave, 'ta_cdlhighwave', 'HIGHWAVE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1837 gnuplot => \&_plot_gnuplot_candlestick,
1838 highcharts => \&_plot_highcharts_candlestick,
1839 },
1840 cdlhikkake => {
1841 name => 'Hikkake Pattern',
1842 params => [],
1843 input => [qw(open high low close)],
1844 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlhikkake, 'ta_cdlhikkake', 'HIKKAKE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1845 gnuplot => \&_plot_gnuplot_candlestick,
1846 highcharts => \&_plot_highcharts_candlestick,
1847 },
1848 cdlhikkakemod => {
1849 name => 'Modified Hikkake Pattern',
1850 params => [],
1851 input => [qw(open high low close)],
1852 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlhikkakemod, 'ta_cdlhikkakemod', 'HIKKAKEMOD', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1853 gnuplot => \&_plot_gnuplot_candlestick,
1854 highcharts => \&_plot_highcharts_candlestick,
1855 },
1856 cdlhomingpigeon => {
1857 name => 'Homing Pigeon',
1858 params => [],
1859 input => [qw(open high low close)],
1860 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlhomingpigeon, 'ta_cdlhomingpigeon', 'HOMINGPIGEON', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1861 gnuplot => \&_plot_gnuplot_candlestick,
1862 highcharts => \&_plot_highcharts_candlestick,
1863 },
1864 cdlidentical3crows => {
1865 name => 'Identical Three Crows',
1866 params => [],
1867 input => [qw(open high low close)],
1868 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlidentical3crows, 'ta_cdlidentical3crows', 'ID3CROWS', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1869 gnuplot => \&_plot_gnuplot_candlestick,
1870 highcharts => \&_plot_highcharts_candlestick,
1871 },
1872 cdlinneck => {
1873 name => 'In-Neck Pattern',
1874 params => [],
1875 input => [qw(open high low close)],
1876 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlinneck, 'ta_cdlinneck', 'IN-NECK', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1877 gnuplot => \&_plot_gnuplot_candlestick,
1878 highcharts => \&_plot_highcharts_candlestick,
1879 },
1880 cdlinvertedhammer => {
1881 name => 'Inverted Hammer',
1882 params => [],
1883 input => [qw(open high low close)],
1884 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlinvertedhammer, 'ta_cdlinvertedhammer', 'INVHAMMER', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1885 gnuplot => \&_plot_gnuplot_candlestick,
1886 highcharts => \&_plot_highcharts_candlestick,
1887 },
1888 cdlkicking => {
1889 name => 'Kicking',
1890 params => [],
1891 input => [qw(open high low close)],
1892 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlkicking, 'ta_cdlkicking', 'KICKING', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1893 gnuplot => \&_plot_gnuplot_candlestick,
1894 highcharts => \&_plot_highcharts_candlestick,
1895 },
1896 cdlkickingbylength => {
1897 name => 'Kicking - Marubozu Length based',
1898 params => [],
1899 input => [qw(open high low close)],
1900 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlkickingbylength, 'ta_cdlkickingbylength', 'KICKLEN', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1901 gnuplot => \&_plot_gnuplot_candlestick,
1902 highcharts => \&_plot_highcharts_candlestick,
1903 },
1904 cdlladderbottom => {
1905 name => 'Ladder Bottom',
1906 params => [],
1907 input => [qw(open high low close)],
1908 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlladderbottom, 'ta_cdlladderbottom', 'LADDERBTM', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1909 gnuplot => \&_plot_gnuplot_candlestick,
1910 highcharts => \&_plot_highcharts_candlestick,
1911 },
1912 cdllongleggeddoji => {
1913 name => 'Long Legged Doji',
1914 params => [],
1915 input => [qw(open high low close)],
1916 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdllongleggeddoji, 'ta_cdllongleggeddoji', 'LONGDOJI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1917 gnuplot => \&_plot_gnuplot_candlestick,
1918 highcharts => \&_plot_highcharts_candlestick,
1919 },
1920 cdllongline => {
1921 name => 'Long Line Candle',
1922 params => [],
1923 input => [qw(open high low close)],
1924 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdllongline, 'ta_cdllongline', 'LONGLINE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1925 gnuplot => \&_plot_gnuplot_candlestick,
1926 highcharts => \&_plot_highcharts_candlestick,
1927 },
1928 cdlmarubozu => {
1929 name => 'Marubozu',
1930 params => [],
1931 input => [qw(open high low close)],
1932 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlmarubozu, 'ta_cdlmarubozu', 'MARUBOZU', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1933 gnuplot => \&_plot_gnuplot_candlestick,
1934 highcharts => \&_plot_highcharts_candlestick,
1935 },
1936 cdlmatchinglow => {
1937 name => 'Matching Low',
1938 params => [],
1939 input => [qw(open high low close)],
1940 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlmatchinglow, 'ta_cdlmatchinglow', 'MATCHLOW', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1941 gnuplot => \&_plot_gnuplot_candlestick,
1942 highcharts => \&_plot_highcharts_candlestick,
1943 },
1944 cdlmathold => {
1945 name => 'Mat Hold',
1946 input => [qw(open high low close)],
1947 params => [
1948 # key, pretty name, type, default value
1949 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.5],
1950 ],
1951 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlmathold, 'ta_cdlmathold', 'MATHOLD', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1952 gnuplot => \&_plot_gnuplot_candlestick,
1953 highcharts => \&_plot_highcharts_candlestick,
1954 },
1955 cdlmorningdojistar => {
1956 name => 'Morning Doji Star',
1957 input => [qw(open high low close)],
1958 params => [
1959 # key, pretty name, type, default value
1960 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.3],
1961 ],
1962 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlmorningdojistar, 'ta_cdlmorningdojistar', 'MORNDOJISTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1963 gnuplot => \&_plot_gnuplot_candlestick,
1964 highcharts => \&_plot_highcharts_candlestick,
1965 },
1966 cdlmorningstar => {
1967 name => 'Morning Star',
1968 input => [qw(open high low close)],
1969 params => [
1970 # key, pretty name, type, default value
1971 [ 'InPenetration', 'Percentage of penetration of candles (>=0)', PDL::double, 0.3],
1972 ],
1973 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlmorningstar, 'ta_cdlmorningstar', 'MORNINGSTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1974 gnuplot => \&_plot_gnuplot_candlestick,
1975 highcharts => \&_plot_highcharts_candlestick,
1976 },
1977 cdlonneck => {
1978 name => 'On-Neck Pattern',
1979 params => [],
1980 input => [qw(open high low close)],
1981 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlonneck, 'ta_cdlonneck', 'ON-NECK', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1982 gnuplot => \&_plot_gnuplot_candlestick,
1983 highcharts => \&_plot_highcharts_candlestick,
1984 },
1985 cdlpiercing => {
1986 name => 'Piercing Pattern',
1987 params => [],
1988 input => [qw(open high low close)],
1989 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlpiercing, 'ta_cdlpiercing', 'PIERCING', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1990 gnuplot => \&_plot_gnuplot_candlestick,
1991 highcharts => \&_plot_highcharts_candlestick,
1992 },
1993 cdlrickshawman => {
1994 name => 'Rickshaw Man',
1995 params => [],
1996 input => [qw(open high low close)],
1997 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlrickshawman, 'ta_cdlrickshawman', 'RICKSHAW', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1998 gnuplot => \&_plot_gnuplot_candlestick,
1999 highcharts => \&_plot_highcharts_candlestick,
2000 },
2001 cdlrisefall3methods => {
2002 name => 'Rising/Falling Three Methods',
2003 params => [],
2004 input => [qw(open high low close)],
2005 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlrisefall3methods, 'ta_cdlrisefall3methods', 'RISEFALL3M', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2006 gnuplot => \&_plot_gnuplot_candlestick,
2007 highcharts => \&_plot_highcharts_candlestick,
2008 },
2009 cdlseparatinglines => {
2010 name => 'Separating Lines',
2011 params => [],
2012 input => [qw(open high low close)],
2013 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlseparatinglines, 'ta_cdlseparatinglines', 'SEPARATELINES', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2014 gnuplot => \&_plot_gnuplot_candlestick,
2015 highcharts => \&_plot_highcharts_candlestick,
2016 },
2017 cdlshootingstar => {
2018 name => 'Shooting Star',
2019 params => [],
2020 input => [qw(open high low close)],
2021 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlshootingstar, 'ta_cdlshootingstar', 'SHOOTINGSTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2022 gnuplot => \&_plot_gnuplot_candlestick,
2023 highcharts => \&_plot_highcharts_candlestick,
2024 },
2025 cdlshortline => {
2026 name => 'Short Line Candle',
2027 params => [],
2028 input => [qw(open high low close)],
2029 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlshortline, 'ta_cdlshortline', 'SHORTLINE', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2030 gnuplot => \&_plot_gnuplot_candlestick,
2031 highcharts => \&_plot_highcharts_candlestick,
2032 },
2033 cdlspinningtop => {
2034 name => 'Spinning Top',
2035 params => [],
2036 input => [qw(open high low close)],
2037 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlspinningtop, 'ta_cdlspinningtop', 'SPINTOP', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2038 gnuplot => \&_plot_gnuplot_candlestick,
2039 highcharts => \&_plot_highcharts_candlestick,
2040 },
2041 cdlstalledpattern => {
2042 name => 'Stalled Pattern',
2043 params => [],
2044 input => [qw(open high low close)],
2045 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlstalledpattern, 'ta_cdlstalledpattern', 'STALLED', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2046 gnuplot => \&_plot_gnuplot_candlestick,
2047 highcharts => \&_plot_highcharts_candlestick,
2048 },
2049 cdlsticksandwich => {
2050 name => 'Stick Sandwich',
2051 params => [],
2052 input => [qw(open high low close)],
2053 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlsticksandwich, 'ta_cdlsticksandwich', 'SANDWICH', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2054 gnuplot => \&_plot_gnuplot_candlestick,
2055 highcharts => \&_plot_highcharts_candlestick,
2056 },
2057 cdltakuri => {
2058 name => 'Takuri',
2059 params => [],
2060 input => [qw(open high low close)],
2061 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdltakuri, 'ta_cdltakuri', 'TAKURI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2062 gnuplot => \&_plot_gnuplot_candlestick,
2063 highcharts => \&_plot_highcharts_candlestick,
2064 },
2065 cdltasukigap => {
2066 name => 'Tasuki Gap',
2067 params => [],
2068 input => [qw(open high low close)],
2069 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdltasukigap, 'ta_cdltasukigap', 'TASUKI', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2070 gnuplot => \&_plot_gnuplot_candlestick,
2071 highcharts => \&_plot_highcharts_candlestick,
2072 },
2073 cdlthrusting => {
2074 name => 'Thrusting Pattern',
2075 params => [],
2076 input => [qw(open high low close)],
2077 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlthrusting, 'ta_cdlthrusting', 'THRUSTING', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2078 gnuplot => \&_plot_gnuplot_candlestick,
2079 highcharts => \&_plot_highcharts_candlestick,
2080 },
2081 cdltristar => {
2082 name => 'Tristar Pattern',
2083 params => [],
2084 input => [qw(open high low close)],
2085 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdltristar, 'ta_cdltristar', 'TRISTAR', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2086 gnuplot => \&_plot_gnuplot_candlestick,
2087 highcharts => \&_plot_highcharts_candlestick,
2088 },
2089 cdlunique3river => {
2090 name => 'Unique Three River',
2091 params => [],
2092 input => [qw(open high low close)],
2093 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlunique3river, 'ta_cdlunique3river', 'U3RIVER', @_); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2094 gnuplot => \&_plot_gnuplot_candlestick,
2095 highcharts => \&_plot_highcharts_candlestick,
2096 },
2097 cdlupsidegap2crows => {
2098 name => 'Upside Gap Two Crows',
2099 params => [],
2100 input => [qw(open high low close)],
2101 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlupsidegap2crows, 'ta_cdlupsidegap2crows', 'UPSIDEGAP2CROWS'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2102 gnuplot => \&_plot_gnuplot_candlestick,
2103 highcharts => \&_plot_highcharts_candlestick,
2104 },
2105 cdlxsidegap3methods => {
2106 name => 'Upside/Downside Gap Three Methods',
2107 params => [],
2108 input => [qw(open high low close)],
2109 0 ▶ code => sub { return shift->_execute_candlestick(\&PDL::ta_cdlxsidegap3methods, 'ta_cdlxsidegap3methods', 'XSIDEGAP3M'); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2110 2 gnuplot => \&_plot_gnuplot_candlestick,
2111 highcharts => \&_plot_highcharts_candlestick,
2112 },
2113 };
2114  
2115 has statistic => {
2116 beta => {
2117 name => 'Beta',
2118 params => [
2119 # key, pretty name, type, default value
2120 [ 'InTimePeriod', 'Period Window (1 - 100000)', PDL::long, 5],
2121 # this is a special key and if you change this will break
2122 # functionality in the gui.pm file.
2123 [ 'CompareWith', 'Compare With Security', PDL::byte, '' ],
2124 ],
2125 input => [qw/close/],
2126 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2127 0 my ($obj, $inpdl1, $inpdl2, $period, $name) = @_;
2128 0 $log->debug("Executing ta_beta with parameters: $period and $name");
2129 0 ▶ if ($inpdl1->dim(0) != $inpdl2->dim(0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inpdl1->dim(0) != $inpdl2->dim(0)) 0 0 0
2130 0 $log->error("Cannot compare unless the sizes of the PDLs are same");
2131 0 return;
2132 }
2133 0 my $outpdl = PDL::ta_beta($inpdl1, $inpdl2, $period);
2134 return [
2135 0 ["BETA($period)", $outpdl, undef, "beta_$period"],
2136 [$name, $inpdl2, { axes => 'x1y2' }, "$name\_close"],
2137 ];
2138 },
2139 gnuplot => \&_plot_gnuplot_compare,
2140 highcharts => \&_plot_highcharts_compare,
2141 },
2142 correl => {
2143 name => q/Pearson's Correlation Coefficient/,
2144 params => [
2145 # key, pretty name, type, default value
2146 [ 'InTimePeriod', 'Period Window (1 - 100000)', PDL::long, 5],
2147 # this is a special key and if you change this will break
2148 # functionality in the gui.pm file.
2149 [ 'CompareWith', 'Compare With Security', PDL::byte, '' ],
2150 ],
2151 input => [qw/close/],
2152 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2153 0 my ($obj, $inpdl1, $inpdl2, $period, $name) = @_;
2154 0 $log->debug("Executing ta_beta with parameters: $period and $name");
2155 0 ▶ if ($inpdl1->dim(0) != $inpdl2->dim(0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inpdl1->dim(0) != $inpdl2->dim(0)) 0 0 0
2156 0 $log->error("Cannot compare unless the sizes of the PDLs are same");
2157 0 return;
2158 }
2159 0 my $outpdl = PDL::ta_correl($inpdl1, $inpdl2, $period);
2160 return [
2161 0 ["CORRELATION($period)", $outpdl, undef, "correl_$period"],
2162 [$name, $inpdl2, { axes => 'x1y2' }, "$name\_close"],
2163 ];
2164 },
2165 gnuplot => \&_plot_gnuplot_compare,
2166 highcharts => \&_plot_highcharts_compare,
2167 },
2168 linearreg => {
2169 name => 'Linear Regression',
2170 params => [
2171 # key, pretty name, type, default value
2172 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2173 ],
2174 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2175 0 my ($obj, $inpdl, @args) = @_;
2176 0 $log->debug("Executing ta_linearreg with parameters", dumper(\@args));
2177 0 my $period = $args[0];
2178 0 my $outpdl = PDL::ta_linearreg($inpdl, @args);
2179 return [
2180 0 ["REGRESSION($period)", $outpdl, undef, "linreg_$period"],
2181 ];
2182 },
2183 gnuplot => \&_plot_gnuplot_general,
2184 highcharts => \&_plot_highcharts_general,
2185 },
2186 linearreg_angle => {
2187 name => 'Linear Regression Angle',
2188 params => [
2189 # key, pretty name, type, default value
2190 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2191 ],
2192 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2193 0 my ($obj, $inpdl, @args) = @_;
2194 0 $log->debug("Executing ta_linearreg_angle with parameters", dumper(\@args));
2195 0 my $period = $args[0];
2196 0 my $outpdl = PDL::ta_linearreg_angle($inpdl, @args);
2197 return [
2198 0 ["REGRESSION ANGLE($period)", $outpdl, { axes => 'x1y2' }, "linregangle_$period"],
2199 ];
2200 },
2201 gnuplot => \&_plot_gnuplot_general,
2202 highcharts => \&_plot_highcharts_general,
2203 },
2204 linearreg_intercept => {
2205 name => 'Linear Regression Intercept',
2206 params => [
2207 # key, pretty name, type, default value
2208 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2209 ],
2210 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2211 0 my ($obj, $inpdl, @args) = @_;
2212 0 $log->debug("Executing ta_linearreg_intercept with parameters", dumper(\@args));
2213 0 my $period = $args[0];
2214 0 my $outpdl = PDL::ta_linearreg_intercept($inpdl, @args);
2215 return [
2216 0 ["REGRESSION INTERCEPT($period)", $outpdl, undef, "linregint_$period"],
2217 ];
2218 },
2219 gnuplot => \&_plot_gnuplot_general,
2220 highcharts => \&_plot_highcharts_general,
2221 },
2222 linearreg_slope => {
2223 name => 'Linear Regression Slope',
2224 params => [
2225 # key, pretty name, type, default value
2226 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2227 ],
2228 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2229 0 my ($obj, $inpdl, @args) = @_;
2230 0 $log->debug("Executing ta_linearreg_slope with parameters", dumper(\@args));
2231 0 my $period = $args[0];
2232 0 my $outpdl = PDL::ta_linearreg_slope($inpdl, @args);
2233 return [
2234 0 ["REGRESSION SLOPE($period)", $outpdl, { axes => 'x1y2' }, "linregslope_$period"],
2235 ];
2236 },
2237 gnuplot => \&_plot_gnuplot_additional,
2238 highcharts => \&_plot_highcharts_additional,
2239 },
2240 linearreg_tsf => {
2241 name => 'Linear Regression - Forecast',
2242 params => [
2243 # key, pretty name, type, default value
2244 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2245 ],
2246 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2247 0 my ($obj, $inpdl, @args) = @_;
2248 0 $log->debug("Executing ta_tsf with parameters", dumper(\@args));
2249 0 my $period = $args[0];
2250 0 my $outpdl = PDL::ta_tsf($inpdl, @args);
2251 return [
2252 0 ["FORECAST($period)", $outpdl, undef, "forecast_$period"],
2253 ];
2254 },
2255 gnuplot => \&_plot_gnuplot_general,
2256 highcharts => \&_plot_highcharts_general,
2257 },
2258 stddev => {
2259 name => 'Standard Deviation',
2260 params => [
2261 # key, pretty name, type, default value
2262 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 5],
2263 [ 'InNbDev', 'No. of Deviations', PDL::double, 1.0],
2264 ],
2265 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2266 0 my ($obj, $inpdl, @args) = @_;
2267 0 $log->debug("Executing ta_stddev with parameters", dumper(\@args));
2268 0 my $period = $args[0];
2269 0 my $num = $args[1];
2270 0 my $outpdl = PDL::ta_stddev($inpdl, @args);
2271 return [
2272 0 ["$num x STD.DEV.($period)", $outpdl, undef, "stddev_$num\_$period"],
2273 ];
2274 },
2275 gnuplot => \&_plot_gnuplot_additional,
2276 highcharts => \&_plot_highcharts_additional,
2277 },
2278 var => {
2279 name => 'Variance',
2280 params => [
2281 # key, pretty name, type, default value
2282 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 5],
2283 [ 'InNbDev', 'No. of Deviations', PDL::double, 1.0],
2284 ],
2285 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2286 0 my ($obj, $inpdl, @args) = @_;
2287 0 $log->debug("Executing ta_var with parameters", dumper(\@args));
2288 0 my $period = $args[0];
2289 0 my $num = $args[1];
2290 0 my $outpdl = PDL::ta_var($inpdl, @args);
2291 return [
2292 0 ["$num x VARIANCE($period)", $outpdl, undef, "var_$num\_$period"],
2293 ];
2294 },
2295 2 gnuplot => \&_plot_gnuplot_additional,
2296 highcharts => \&_plot_highcharts_additional,
2297 },
2298 };
2299  
2300 has price => {
2301 midpoint => {
2302 name => 'Mid-point over period',
2303 params => [
2304 # key, pretty name, type, default value
2305 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2306 ],
2307 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2308 0 my ($obj, $inpdl, @args) = @_;
2309 0 $log->debug("Executing ta_midpoint with parameters: ", dumper(\@args));
2310 0 my $period = $args[0];
2311 0 my $outpdl = PDL::ta_midpoint($inpdl, @args);
2312 return [
2313 0 ["MIDPOINT($period)", $outpdl, undef, "midpt_$period"],
2314 ];
2315 },
2316 gnuplot => \&_plot_gnuplot_general,
2317 highcharts => \&_plot_highcharts_general,
2318 },
2319 midprice => {
2320 name => 'Mid-point Price over period',
2321 params => [
2322 # key, pretty name, type, default value
2323 [ 'InTimePeriod', 'Period Window (2 - 100000)', PDL::long, 14],
2324 ],
2325 input => ['high', 'low'],
2326 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2327 0 my ($obj, $highpdl, $lowpdl, @args) = @_;
2328 0 $log->debug("Executing ta_midprice parameters: ", dumper(\@args));
2329 0 my $period = $args[0];
2330 0 my $outpdl = PDL::ta_midprice($highpdl, $lowpdl, @args);
2331 return [
2332 0 ["MIDPRICE($period)", $outpdl, undef, "midpx_$period"],
2333 ];
2334 },
2335 gnuplot => \&_plot_gnuplot_general,
2336 highcharts => \&_plot_highcharts_general,
2337 },
2338 avgprice => {
2339 name => 'Average Price',
2340 params => [
2341 # no params
2342 ],
2343 input => [qw/open high low close/],
2344 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2345 0 my ($obj, $open, $high, $low, $close) = @_;
2346 0 $log->debug("Executing ta_avgprice");
2347 0 my $outpdl = PDL::ta_avgprice($open, $high, $low, $close);
2348 return [
2349 0 ["Avg. Price", $outpdl, undef, "avgpx"],
2350 ];
2351 },
2352 gnuplot => \&_plot_gnuplot_general,
2353 highcharts => \&_plot_highcharts_general,
2354 },
2355 medprice => {
2356 name => 'Median Price',
2357 params => [
2358 # no params
2359 ],
2360 input => [qw/high low/],
2361 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2362 0 my ($obj, $high, $low) = @_;
2363 0 $log->debug("Executing ta_medprice");
2364 0 my $outpdl = PDL::ta_medprice($high, $low);
2365 return [
2366 0 ["Median Price", $outpdl, undef, "medianpx"],
2367 ];
2368 },
2369 gnuplot => \&_plot_gnuplot_general,
2370 highcharts => \&_plot_highcharts_general,
2371 },
2372 typprice => {
2373 name => 'Typical Price',
2374 params => [
2375 # no params
2376 ],
2377 input => [qw/high low close/],
2378 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2379 0 my ($obj, $high, $low, $close) = @_;
2380 0 $log->debug("Executing ta_typprice");
2381 0 my $outpdl = PDL::ta_typprice($high, $low, $close);
2382 return [
2383 0 ["Typical Price", $outpdl, undef, "typpx"],
2384 ];
2385 },
2386 gnuplot => \&_plot_gnuplot_general,
2387 highcharts => \&_plot_highcharts_general,
2388 },
2389 wclprice => {
2390 name => 'Weighted Close Price',
2391 params => [
2392 # no params
2393 ],
2394 input => [qw/high low close/],
2395 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2396 0 my ($obj, $high, $low, $close) = @_;
2397 0 $log->debug("Executing ta_wclprice");
2398 0 my $outpdl = PDL::ta_wclprice($high, $low, $close);
2399 return [
2400 0 ["Wt. Close Price", $outpdl, undef, "wclpx"],
2401 ];
2402 },
2403 2 gnuplot => \&_plot_gnuplot_general,
2404 highcharts => \&_plot_highcharts_general,
2405 },
2406 };
2407  
2408 2 has group_name => {
2409 overlaps => 'Overlap Studies',
2410 momentum => 'Momentum Indicators',
2411 volatility => 'Volatility Indicators',
2412 volume => 'Volume Indicators',
2413 statistic => 'Statistic Functions',
2414 price => 'Price Transform',
2415 hilbert => 'Hilbert Transform',
2416 candlestick => 'Candlestick Patterns',
2417 };
2418  
2419 2 has group_key => {
2420 'Overlap Studies' => 'overlaps',
2421 'Momentum Indicators' => 'momentum',
2422 'Volatility Indicators' => 'volatility',
2423 'Volume Indicators' => 'volume',
2424 'Statistic Functions' => 'statistic',
2425 'Price Transform' => 'price',
2426 'Hilbert Transform' => 'hilbert',
2427 'Candlestick Patterns' => 'candlestick',
2428 };
2429  
2430 0 ▶sub get_groups {
Subroutine get_groups: not called CC=2 SCAR=17.9
Pod undocumented
2431 0 my $self = shift;
2432 ## NEEDS TO BE IN THIS ORDER
2433 0 my @groups = (
2434 'Overlap Studies',
2435 'Momentum Indicators',
2436 'Volatility Indicators',
2437 'Volume Indicators',
2438 'Statistic Functions',
2439 'Price Transform',
2440 'Hilbert Transform',
2441 'Candlestick Patterns',
2442 );
2443 0 ▶ return wantarray ? @groups : \@groups;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2444 }
2445  
2446 0 ▶sub get_funcs($) {
Subroutine get_funcs: not called CC=6 SCAR=37.4
Pod undocumented
2447 0 my ($self, $grp) = @_;
2448 0 ▶ $grp = $self->group_key->{$grp} if defined $grp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $grp 0 0 0
2449 0 ▶ if (defined $grp and $self->has($grp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grp and $self->has($grp)) 0 0 0
Condition0%0/3
defined $grp and $self->has($grp)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $grp and $self->has($grp)
defined $grp $self->has($grp)
Truth table0%0/3
A and B
A= defined $grpB= $self->has($grp)
ABresult
0X0
100
111
2450 0 my $r = $self->$grp;
2451 0 my @funcs = ();
2452 0 foreach my $k (sort(keys %$r)) {
2453 0 push @funcs, $r->{$k}->{name};
2454 }
2455 0 $log->debug("Found funcs: ", dumper(\@funcs));
2456 0 ▶ return wantarray ? @funcs : \@funcs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2457 }
2458 }
2459  
2460 0 ▶sub get_params($$) {
Subroutine get_params: not called CC=8 SCAR=42.8
Pod undocumented
2461 0 my ($self, $fn_name, $grp) = @_;
2462 0 ▶ $grp = $self->group_key->{$grp} if defined $grp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $grp 0 0 0
2463 0 my $fn;
2464 # find the function parameters
2465 0 ▶ if (defined $grp and $self->has($grp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grp and $self->has($grp)) 0 0 0
Condition0%0/3
defined $grp and $self->has($grp)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $grp and $self->has($grp)
defined $grp $self->has($grp)
Truth table0%0/3
A and B
A= defined $grpB= $self->has($grp)
ABresult
0X0
100
111
2466 0 my $r = $self->$grp;
2467 0 foreach my $k (sort (keys %$r)) {
2468 0 ▶ $fn = $k if $r->{$k}->{name} eq $fn_name;
Branch: 1 branch
BranchTrueFalseTotal
if $r->{$k}{"name"} eq $fn_name 0 0 0
2469 0 ▶ last if defined $fn;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fn 0 0 0
2470 }
2471 0 ▶ my $params = $r->{$fn}->{params} if defined $fn;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fn 0 0 0
2472 0 $log->debug("Found params: ", dumper($params));
2473 0 return $params;
2474 }
2475 }
2476  
2477 1 ▶sub _find_func_key($$) {
Subroutine _find_func_key: called CC=10 SCAR=24.5
2478 1 my ($self, $iref) = @_;
2479 1 ▶ return unless ref $iref eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $iref eq "HASH" 0 1 1
2480 1 my $params = $iref->{params};
2481 1 my $fn_name = $iref->{func};
2482 1 my $fn_key;
2483 1 ▶ my $grp = $self->group_key->{$iref->{group}} if defined $iref->{group};
Branch: 1 branch
BranchTrueFalseTotal
if defined $iref->{"group"} 1 0 1
2484 1 ▶ if (defined $grp and $self->has($grp) and $fn_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grp and $self->has($grp) and $fn_name) 1 0 1
Condition33%2/6
defined $grp and $self->has($grp) and $fn_name
!ll&&!rl&&r
001
defined $grp and $self->has($grp)
!ll&&!rl&&r
001
MC/DC0%0/3
defined $grp and $self->has($grp) and $fn_name
defined $grp $self->has($grp) $fn_name
Truth table25%1/4
A and B and C
A= defined $grpB= $self->has($grp)C= $fn_name
ABCresult
0XX0
10X0
1100
1111
2485 1 my $r = $self->$grp;
2486 1 foreach my $k (sort (keys %$r)) {
2487 12 ▶ $fn_key = $k if $r->{$k}->{name} eq $fn_name;
Branch: 1 branch
BranchTrueFalseTotal
if $r->{$k}{"name"} eq $fn_name 1 11 12
2488 12 ▶ last if defined $fn_key;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fn_key 1 11 12
2489 }
2490 }
2491 1 ▶ return unless defined $fn_key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fn_key 0 1 1
2492 1 $log->debug("Found function key: $fn_key");
2493 1 return $fn_key;
2494 }
2495  
2496 1 ▶sub execute_ohlcv($$) {
Subroutine execute_ohlcv: called CC=27 SCAR=44.9
Pod undocumented
2497 1 my ($self, $data, $iref, $data2) = @_;
2498 1 ▶ return unless ref $data eq 'PDL';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "PDL" 0 1 1
2499 1 my $fn_key = $self->_find_func_key($iref);
2500 1 ▶ return unless defined $fn_key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fn_key 0 1 1
2501 # ok now we found the function so let's invoke it
2502 1 ▶ my $grp = $self->group_key->{$iref->{group}} if defined $iref->{group};
Branch: 1 branch
BranchTrueFalseTotal
if defined $iref->{"group"} 1 0 1
2503 1 ▶ return unless defined $grp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $grp 0 1 1
2504 1 my $params = $iref->{params};
2505 1 my $func = $self->$grp->{$fn_key}->{func};
2506 1 my $coderef = $self->$grp->{$fn_key}->{code};
2507 1 my $paramarray = $self->$grp->{$fn_key}->{params};
2508 1 my @args = ();
2509 1 ▶ for (my $i = 0; $i < scalar @$paramarray; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$paramarray) 1 1 2
2510 1 my $k = $paramarray->[$i]->[0];
2511 1 ▶ next unless defined $k;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 1 1
2512 1 ▶ if (exists $params->{$k . '_index'}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $$params{$k . '_index'}) { } 0 1 1
elsif (exists $$params{$k . '_pdl'}) { } 0 1 1
elsif ($k =~ /CompareWith/i) { } 0 1 1
2513 # handle ARRAY
2514 0 push @args, $params->{$k . '_index'};
2515 } elsif (exists $params->{$k . '_pdl'}) {
2516 0 my $csv = $params->{$k};
2517 0 ▶ $csv =~ s/\s//g if length $csv;
Branch: 1 branch
BranchTrueFalseTotal
if length $csv 0 0 0
2518 0 ▶ my @a = split /,/, $csv if length $csv;
Branch: 1 branch
BranchTrueFalseTotal
if length $csv 0 0 0
2519 0 ▶ push @args, pdl(@a) if @a;
Branch: 1 branch
BranchTrueFalseTotal
if @a 0 0 0
2520 0 ▶ push @args, PDL::null unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 0 0
2521 } elsif ($k =~ /CompareWith/i) {
2522 # dont eval it
2523 0 push @args, $params->{$k};
2524 } else {
2525 1 push @args, eval $params->{$k};
2526 }
2527 }
2528 1 ▶ my $input_cols = $self->$grp->{$fn_key}->{input} || ['close'];
Condition50%1/2
$self->$grp->{$fn_key}{'input'} || ['close']
l!l
01
MC/DC0%0/1
$self->$grp->{$fn_key}{'input'} || ['close']
$self->$grp->{$fn_key}{'input'}
Truth table50%1/2
A
A= $self->$grp->{$fn_key}{'input'}
Aresult
11
00
2529 1 ▶ $input_cols = ['close'] unless scalar @$input_cols;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$input_cols 0 1 1
2530 1 my @input_pdls = ();
2531 1 foreach (@$input_cols) {
2532 1 ▶ push @input_pdls, $data(,(0)) if $_ eq 'time';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "time" 0 1 1
2533 1 ▶ push @input_pdls, $data(,(1)) if $_ eq 'open';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "open" 0 1 1
2534 1 ▶ push @input_pdls, $data(,(2)) if $_ eq 'high';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "high" 0 1 1
2535 1 ▶ push @input_pdls, $data(,(3)) if $_ eq 'low';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "low" 0 1 1
2536 1 ▶ push @input_pdls, $data(,(4)) if $_ eq 'close';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "close" 1 0 1
2537 1 ▶ push @input_pdls, $data(,(5)) if $_ eq 'volume';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "volume" 0 1 1
2538 }
2539 1 ▶ if (defined $data2 and ref $data2 eq 'PDL') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data2 and ref $data2 eq "PDL") 0 1 1
Condition33%1/3
defined $data2 and ref $data2 eq "PDL"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $data2 and ref $data2 eq "PDL"
defined $data2 ref $data2 eq "PDL"
Truth table33%1/3
A and B
A= defined $data2B= ref $data2 eq "PDL"
ABresult
0X0
100
111
2540 0 push @input_pdls, $data2(,(4)); # always use close
2541 0 $log->debug("Adding close2 price");
2542 }
2543 1 ▶ unless (scalar @input_pdls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @input_pdls) 0 1 1
2544 0 $log->warn("These input columns are not supported yet: ", dumper($input_cols));
2545 0 return;
2546 }
2547 1 ▶ return &$coderef($self, @input_pdls, @args) if ref $coderef eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $coderef eq "CODE" 1 0 1
2548 }
2549  
2550 0 ▶sub get_plot_args($$$) {
Subroutine get_plot_args: not called CC=6 SCAR=37.4
Pod undocumented
2551 0 my ($self, $xdata, $output, $iref) = @_;
2552 0 my $fn_key = $self->_find_func_key($iref);
2553 0 ▶ return unless defined $fn_key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fn_key 0 0 0
2554 0 ▶ my $grp = $self->group_key->{$iref->{group}} if defined $iref->{group};
Branch: 1 branch
BranchTrueFalseTotal
if defined $iref->{"group"} 0 0 0
2555 0 ▶ return unless defined $grp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $grp 0 0 0
2556 0 my $plotref = $self->$grp->{$fn_key}->{lc($self->plot_engine)};
2557 0 ▶ $log->warn("There is no plotting function available for $fn_key") unless ref $plotref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plotref eq "CODE" 0 0 0
2558 0 ▶ return &$plotref($self, $xdata, $output) if ref $plotref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $plotref eq "CODE" 0 0 0
2559 }
2560  
2561 2 has buysell => {
2562 gnuplot => \&_plot_gnuplot_buysell,
2563 ## DO NOT USE
2564 highcharts => \&_plot_highcharts_buysell,
2565 };
2566  
2567 0 ▶sub get_plot_args_buysell {
Subroutine get_plot_args_buysell: not called CC=6 SCAR=37.4
Pod undocumented
2568 0 my ($self, $xdata, $buys, $sells, $rtpnl) = @_;
2569 0 my $plotref = $self->buysell->{lc($self->plot_engine)};
2570 0 ▶ $log->warn("There is no plotting function available for buy-sell") unless ref $plotref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plotref eq "CODE" 0 0 0
2571 0 ▶ return undef unless ref $plotref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plotref eq "CODE" 0 0 0
2572 0 my $output = [
2573 # plotting beautifier
2574 [ 'Buys', $buys->setbadif($buys == 0), { with => 'points', pointtype => 5, linecolor => 'green', }, 'buys' ],
2575 [ 'Sells', $sells->setbadif($sells == 0), { with => 'points', pointtype => 7, linecolor => 'red', }, 'sells' ],
2576 ];
2577 0 ▶ if (ref $rtpnl eq 'PDL' and $self->plot_engine =~ /gnuplot/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rtpnl eq 'PDL' and $self->plot_engine =~ /gnuplot/i) { } 0 0 0
Condition0%0/3
ref $rtpnl eq "PDL" and $self->plot_engine =~ /gnuplot/i
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rtpnl eq "PDL" and $self->plot_engine =~ /gnuplot/i
ref $rtpnl eq "PDL" $self->plot_engine =~ /gnuplot/i
Truth table0%0/3
A and B
A= ref $rtpnl eq "PDL"B= $self->plot_engine =~ /gnuplot/i
ABresult
0X0
100
111
2578 0 push @$output, [
2579 'Runtime Profit',
2580 $rtpnl->setbadif($rtpnl <= 0),
2581 {
2582 with => 'filledcurves above y=0 fc "green"',
2583 fillstyle => 'solid',
2584 },
2585 'rtpnl',
2586 ];
2587 0 push @$output, [
2588 'Runtime Drawdown',
2589 $rtpnl->setbadif($rtpnl >= 0),
2590 {
2591 with => 'filledcurves below y=0 fc "red"',
2592 fillstyle => 'solid',
2593 },
2594 'rtpnl',
2595 ];
2596 } else {
2597 0 push @$output, [ 'Runtime P&L', $rtpnl->setbadif($rtpnl == 0), {}, 'rtpnl', ];
2598 }
2599 0 ▶ return &$plotref($self, $xdata, $output) if ref $plotref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $plotref eq "CODE" 0 0 0
2600 }
2601  
2602 0 ▶sub calculate_pnl {
Subroutine calculate_pnl: not called CC=20 SCAR=60.4
Pod undocumented
2603 0 my ($self, $xdata, $pxdata, $buysells) = @_;
2604 0 $log->info("Px: ", $pxdata);
2605 0 my $buys = $buysells->{buys};
2606 0 $log->info("Buys:", $buys);
2607 0 my $sells = $buysells->{sells};
2608 0 $log->info("Sells: ", $sells);
2609 0 ▶ my $qty = $buysells->{quantity} || 100;
Condition0%0/2
$buysells->{'quantity'} || 100
l!l
00
MC/DC0%0/1
$buysells->{'quantity'} || 100
$buysells->{'quantity'}
Truth table0%0/2
A
A= $buysells->{'quantity'}
Aresult
11
00
2610 0 my $b_idx = which( $buys > 0 );
2611 0 my $s_idx = which( $sells > 0 );
2612 0 my $final_buys = zeroes($buys->dim(0));
2613 0 my $final_sells = zeroes($sells->dim(0));
2614 0 my $long_flag = $buysells->{long};
2615 0 my $short_flag = $buysells->{short};
2616 0 $buysells->{shorts_pnl} = 0;
2617 0 $buysells->{longs_pnl} = 0;
2618 0 ▶ $buysells->{quantity} = $qty unless defined $buysells->{quantity};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buysells->{"quantity"} 0 0 0
2619 0 $log->info("buy index: $b_idx\n", $b_idx->info);
2620 0 $log->info("sell index: $s_idx\n", $s_idx->info);
2621 0 ▶ if ($b_idx->dim(0) > $s_idx->dim(0)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($b_idx->dim(0) > $s_idx->dim(0)) { } 0 0 0
elsif ($b_idx->dim(0) < $s_idx->dim(0)) { } 0 0 0
2622 0 $b_idx = $b_idx->index(xvals($s_idx->dim(0)));
2623 0 $log->info("adjusting buy index to $b_idx");
2624 0 $log->info("keeping sell index as $s_idx");
2625 # fix the $buys
2626 } elsif ($b_idx->dim(0) < $s_idx->dim(0)) {
2627 0 $s_idx = $s_idx->index(xvals($b_idx->dim(0)));
2628 0 $log->info("keeping buy index as $b_idx");
2629 0 $log->info("adjusting sell index to $s_idx");
2630 # fix the $sells
2631 }
2632 0 ▶ if ($b_idx->isempty or $s_idx->isempty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_idx->isempty or $s_idx->isempty) 0 0 0
Condition0%0/3
$b_idx->isempty or $s_idx->isempty
l!l&&r!l&&!r
000
MC/DC0%0/2
$b_idx->isempty or $s_idx->isempty
$b_idx->isempty $s_idx->isempty
Truth table0%0/3
A or B
A= $b_idx->isemptyB= $s_idx->isempty
ABresult
1X1
011
000
2633 0 $log->info("no trades possible");
2634 0 return;
2635 }
2636 # numbers of buys and sells are equal
2637 0 ▶ if ( $b_idx->dim(0) == $s_idx->dim(0) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_idx->dim(0) == $s_idx->dim(0)) { } 0 0 0
2638 # long only
2639 0 my $longonly = which( $b_idx < $s_idx );
2640 0 my $shortonly = which( $b_idx > $s_idx );
2641 0 ▶ if ($long_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($long_flag) 0 0 0
2642 0 $log->debug("allow long trades");
2643 0 ▶ unless ( $longonly->isempty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($longonly->isempty) { } 0 0 0
2644 0 $log->debug("long-only index ", $longonly);
2645 0 my $trades = PDL::null;
2646 0 $trades =
2647 $trades->glue( 1, $xdata->index( $b_idx->index($longonly) ) );
2648 0 $trades =
2649 $trades->glue( 1, $buys->index( $b_idx->index($longonly) ) );
2650 0 $trades =
2651 $trades->glue( 1, $xdata->index( $s_idx->index($longonly) ) );
2652 0 $trades =
2653 $trades->glue( 1, $sells->index( $s_idx->index($longonly) ) );
2654 0 $log->debug("Long Trades: $trades");
2655 0 $final_buys->index($b_idx->index($longonly)) .= $buys->index($b_idx->index($longonly));
2656 0 $final_sells->index($s_idx->index($longonly)) .= $sells->index($s_idx->index($longonly));
2657  
2658 # since they are ordered correctly as long only
2659 0 my $pnl = $trades ( , (3) ) - $trades ( , (1) );
2660 0 $pnl = sumover($pnl * $qty);
2661 0 $log->debug("long-only P&L for $qty shares: $pnl");
2662 0 $buysells->{longs} = $trades;
2663 0 $buysells->{longs_pnl} += $pnl;
2664 } else {
2665 0 $log->debug("some long trades possible");
2666 0 my $s2 = $s_idx->copy;
2667 0 my $b2 = $b_idx->copy;
2668 0 $s2->setbadat(0);
2669 0 $b2 = $b2->setbadat(-1)->rotate(1);
2670 0 $longonly = which( $b2 < $s2 );
2671 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
2672 0 $log->info("adjusting sell index to $s2");
2673 0 $log->info("adjusting buy index to $b2");
2674 0 $log->info("long-only index: $longonly");
2675 }
2676 0 ▶ if ($s2->isempty or $b2->isempty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s2->isempty or $b2->isempty) 0 0 0
Condition0%0/3
$s2->isempty or $b2->isempty
l!l&&r!l&&!r
000
MC/DC0%0/2
$s2->isempty or $b2->isempty
$s2->isempty $b2->isempty
Truth table0%0/3
A or B
A= $s2->isemptyB= $b2->isempty
ABresult
1X1
011
000
2677 0 $log->info("no trades possible");
2678 0 return;
2679 }
2680 0 ▶ unless ( $longonly->isempty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($longonly->isempty) { } 0 0 0
2681 0 my $trades = PDL::null;
2682 0 $trades =
2683 $trades->glue( 1, $xdata->index( $b2->index($longonly) ) );
2684 0 $trades =
2685 $trades->glue( 1, $buys->index( $b2->index($longonly) ) );
2686 0 $trades =
2687 $trades->glue( 1, $xdata->index( $s2->index($longonly) ) );
2688 0 $trades =
2689 $trades->glue( 1, $sells->index( $s2->index($longonly) ) );
2690 0 $log->debug("Long Trades: $trades");
2691 0 $final_buys->index($b2->index($longonly)) .= $buys->index($b2->index($longonly));
2692 0 $final_sells->index($s2->index($longonly)) .= $sells->index($s2->index($longonly));
2693  
2694 # since they are ordered correctly as long only
2695 0 my $pnl = $trades ( , (3) ) - $trades ( , (1) );
2696 0 $pnl = sumover($pnl * $qty);
2697 0 $log->debug("long-only P&L for $qty shares: $pnl");
2698 0 $self->debug;
2699 0 $buysells->{longs} = $trades;
2700 0 $buysells->{longs_pnl} += $pnl;
2701 } else {
2702 0 $log->warn("No long trades possible");
2703 }
2704 }
2705 }
2706 0 ▶ if ($short_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short_flag) 0 0 0
2707 0 $log->debug("allow short trades");
2708 0 ▶ unless ( $shortonly->isempty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shortonly->isempty) { } 0 0 0
2709 0 $log->debug("short-only index: $shortonly");
2710 0 my $trades = PDL::null;
2711 0 $trades =
2712 $trades->glue( 1, $xdata->index( $s_idx->index($shortonly) ) );
2713 0 $trades =
2714 $trades->glue( 1, $sells->index( $s_idx->index($shortonly) ) );
2715 0 $trades =
2716 $trades->glue( 1, $xdata->index( $b_idx->index($shortonly) ) );
2717 0 $trades =
2718 $trades->glue( 1, $buys->index( $b_idx->index($shortonly) ) );
2719 0 $log->debug("Short Trades: $trades");
2720 0 $final_buys->index($b_idx->index($shortonly)) .= $buys->index($b_idx->index($shortonly));
2721 0 $final_sells->index($s_idx->index($shortonly)) .= $sells->index($s_idx->index($shortonly));
2722  
2723 # since they are ordered correctly as short only
2724 0 my $pnl = $trades ( , (3) ) - $trades ( , (1) );
2725 0 $pnl = sumover($pnl * $qty);
2726 0 $log->debug("short-only P&L for $qty shares: $pnl");
2727 0 $buysells->{shorts} = $trades;
2728 0 $buysells->{shorts_pnl} += $pnl;
2729 } else {
2730 0 $log->debug("some short trades possible");
2731 0 my $s2 = $s_idx->copy;
2732 0 my $b2 = $b_idx->copy;
2733 0 $b2->setbadat(0);
2734 0 $s2 = $s2->setbadat(-1)->rotate(1);
2735 0 $shortonly = which( $b2 > $s2 );
2736 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
2737 0 $log->debug("adjusting sell index to $s2");
2738 0 $log->info("adjusting buy index to $b2");
2739 0 $log->info("short-only index: $shortonly");
2740 }
2741 0 ▶ if ($s2->isempty or $b2->isempty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s2->isempty or $b2->isempty) 0 0 0
Condition0%0/3
$s2->isempty or $b2->isempty
l!l&&r!l&&!r
000
MC/DC0%0/2
$s2->isempty or $b2->isempty
$s2->isempty $b2->isempty
Truth table0%0/3
A or B
A= $s2->isemptyB= $b2->isempty
ABresult
1X1
011
000
2742 0 $log->info("no trades possible");
2743 0 return;
2744 }
2745 0 ▶ unless ( $shortonly->isempty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shortonly->isempty) { } 0 0 0
2746 0 my $trades = PDL::null;
2747 0 $trades =
2748 $trades->glue( 1, $xdata->index( $s2->index($shortonly) ) );
2749 0 $trades =
2750 $trades->glue( 1, $sells->index( $s2->index($shortonly) ) );
2751 0 $trades =
2752 $trades->glue( 1, $xdata->index( $b2->index($shortonly) ) );
2753 0 $trades =
2754 $trades->glue( 1, $buys->index( $b2->index($shortonly) ) );
2755 0 $log->debug("Short Trades: $trades");
2756 0 $final_buys->index($b2->index($shortonly)) .= $buys->index($b2->index($shortonly));
2757 0 $final_sells->index($s2->index($shortonly)) .= $sells->index($s2->index($shortonly));
2758  
2759 # since they are ordered correctly as long only
2760 0 my $pnl = $trades ( , (3) ) - $trades ( , (1) );
2761 0 $pnl = sumover($pnl * $qty);
2762 0 $log->debug("short-only P&L for $qty shares: $pnl");
2763 0 $buysells->{shorts} = $trades;
2764 0 $buysells->{shorts_pnl} += $pnl;
2765 } else {
2766 0 $log->warn("No short trades possible");
2767 }
2768 }
2769 }
2770 } else {
2771 0 $log->warn("No. of buys and sells are not equal anyway");
2772 0 return $buysells;
2773 }
2774 # swap the original with the final
2775 0 $buysells->{orig_buys} = $buys;
2776 0 $buysells->{orig_sells} = $sells;
2777 0 $buysells->{buys} = $final_buys;
2778 0 $buysells->{sells} = $final_sells;
2779 ## calculate RTPNL
2780 ##TODO: handle short trades
2781 0 my $buyflags = zeroes($final_buys->dim(0));
2782 0 $buyflags->index(which($final_buys > 0)) .= 1; ## set 1 where it is a buy
2783 0 my $sellflags = zeroes($final_sells->dim(0));
2784 0 $sellflags->index(which($final_sells > 0)) .= -1; ## set -1 where it is a sell
2785 0 my $netflags = $buyflags + $sellflags;## spread the buy to each day until sell
2786 0 my $netflags2 = $netflags->cumusumover;
2787 0 $netflags2 = $netflags2 - $sellflags;## move the buy to the sell day as well
2788 0 $log->debug("netflags2: ", $netflags2);
2789 0 my $buypx_daily = locf($final_buys->setbadif($final_buys == 0));
2790 0 $buypx_daily = $buypx_daily * $netflags2;
2791 0 my $px_daily = $pxdata * $netflags2;
2792 0 my $rtpnl = $px_daily - $buypx_daily;
2793 0 $rtpnl *= $qty;
2794 0 $buysells->{rtpnl} = $rtpnl;
2795 0 $log->debug("rtpnl: ", $buysells->{rtpnl});
2796 0 return $buysells;
2797 }
2798  
2799 2 1;
2800 __END__
« App/financeta/data/gemini.pm ↑ Summary App/financeta/data/yahoo.pm »