App-Chart

 view release on metacpan or  search on metacpan

chart  view on Meta::CPAN

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  # Old code:
  #
  # # version 0.06 for bug fix of a struct size for perl 5.10 (there's some
  # # fragile duplication)
  # require Encode;           # Encode::PERLQQ
  # require PerlIO::locale; PerlIO::locale->VERSION(0.06);
  # { no warnings 'once';
  #   local $PerlIO::encoding::fallback = Encode::PERLQQ; # \x{1234} style
  #   (binmode (STDOUT, ':locale') && binmode (STDERR, ':locale'))
  #     or die "Cannot set :encoding on stdout/stderr: $!\n";
  # }
  # Makefile: 'PerlIO::locale' => '0.06',
  # , libperlio-locale-perl (>= 0.06)
}
 
my $option_output;
my $option_mode;
my @args;
 
{

doc/chart.texi  view on Meta::CPAN

2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
@cindex Deviation
@cindex Standard error
 
@cindex Kirshenbaum, Paul
Kirshenbaum bands are channel lines drawn around an exponential moving average
(@pxref{Exponential Moving Average}).  The channel width is a multiple of the
``standard error'' from a linear regression of a past N days (@pxref{Linear
Regression}, and the EMA is smoothed using the same N days.
 
Kirshenbaum bands are similar to Bollinger bands (@pxref{Bollinger Bands}),
but with a linear regression standard error (stderr) instead of a standard
deviation (stddev, @pxref{Standard Deviation}).  The difference is that stddev
takes no account of a trend, so the Bollinger channel widens when a trend is
in progress.  But stderr is based on deviation from a fitted sloping line, so
if prices are making steady progress up or down the channel width remains
small.
 
The standard error values (ie.@: the channel width) can be viewed directly as
an indicator too as ``Linear Regression Stderr'' (@pxref{Linear Regression}).
 
 
@c ---------------------------------------------------------------------------
@node Parabolic SAR,  , Kirshenbaum Bands, Channels and Boxes
@section Parabolic SAR

doc/chart.texi  view on Meta::CPAN

4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
called the @dfn{regression coefficient}.  This is available as an indicator
(Linear Regression Slope), to show how steep the fitted trend line is.  The
units are price change per day, which is negative for a downward sloping line.
This may or may not be particularly useful so it's under ``Low Priority'' in
the indicator lists.
 
@cindex Standard error
@anchor{Linear Regression Standard Error}
@subsection Standard Error
 
Standard error (stderr) is a statistical measure of how much values differ
from an assumed underlying curve.  It's calculated as the quadratic mean of
the vertical distances from each point to the curve.
 
Standard error from a linear regression line @math{y=a+bx} is
 
@tex
$$ Stderr = \sqrt { (y_1 - (a + bx_1))^2 + \cdots + (y_N - (a + bx_N))^2
                    \over N } $$
@end tex
@ifnottex
@example
               / (y1 - (a+b*x1))^2 + ... + (yN - (a+b*xN))^2 \
Stderr = sqrt |  -------------------------------------------  |
               \                     N                       /
@end example
@end ifnottex
 
Notice the numerator is the same SumSquares which was minimized above.
Standard error is similar to standard deviation (@pxref{Standard Deviation});
but where stddev takes differences from a horizontal line (the @math{Y} mean),
stderr here goes from the sloping linear regression line.
 
For reference, there's no need to actually calculate the linear regression
@math{a} and @math{b}, the stderr can be formed directly as
 
@tex
$$ Stderr = \sqrt { Variance(Y) - { Covariance(X,Y)^2 \over Variance(X) }} $$
@end tex
@ifnottex
@example
               /               Covariance(X,Y)^2 \
Stderr = sqrt |  Variance(Y) - -----------------  |
               \                  Variance(X)    /
@end example

doc/chart.texi  view on Meta::CPAN

4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
Standard error from a linear regression like this is used as a channel width
in Kirshenbaum Bands (@pxref{Kirshenbaum Bands}).  It can also be viewed
directly as an indicator, but this is probably of limited use and for that
reason is under ``Low Priority'' in the indicator lists.
 
@subsection Additional Resources
@itemize
@item
stderr without the a,b parameters
@end itemize
 
 
@c ---------------------------------------------------------------------------
@node Standard Deviation, True Range, Linear Regression, Common Calculations
@section Standard Deviation
@cindex Standard deviation
@cindex Stddev
 
Standard deviation (stddev) is a statistical measure of how much the values in

lib/App/Chart/EmacsMain.pm  view on Meta::CPAN

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
binmode (STDIN, ':utf8') or die;
 
# dup-ed to a new descriptor to talk to emacs
open $emacs_fh, '>&STDOUT' or die;
$emacs_fh->autoflush(1); # emacs_write() does single-string prints
 
# ENHANCE-ME: use one of the IO::Capture or via layer or whatnot to get
# perl prints to STDOUT/STDERR and send them up to an emacs buffer, or
# message area
#
# stdout/stderr fds 1 and 2 put to /dev/null to discard other prints
my $devnull = File::Spec->devnull;
fdreopen (1, $devnull, POSIX::O_WRONLY())
  // die "Cannot send STDOUT to $devnull: ", Glib::strerror($!);
POSIX::dup2 (1, 2) // die;
 
if (DEBUG) {
  # fds 1 and 2 changed (again) to DEBUG_TTY_FILENAME, if it's possible to
  # open that
  if (fdreopen (1, DEBUG_TTY_FILENAME, POSIX::O_WRONLY())) {
    POSIX::dup2 (1, 2) // die "Cannot dup fd 1 to fd 2: $!";

lib/App/Chart/Series/Derived/Kirshenbaum.pm  view on Meta::CPAN

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
sub manual    { __p('manual-node','Kirshenbaum Bands') }
 
  { type       => 'average',
    parameter_info => [ { name    => __('Days'),
                          key     => 'kirshenbaum_days',
                          type    => 'integer',
                          minimum => 1,
                          default => 20 },
                        { name     => __('Stderrs'),
                          key      => 'kirshenbaum_stderrs',
                          type     => 'float',
                          default  => 1.75,
                          decimals => 2,
                          step     => 0.25,
                          minimum  => 0 }],
    line_colours => { upper => App::Chart::BAND_COLOUR(),
                      lower => App::Chart::BAND_COLOUR() },
  };
 
sub new {
  my ($class, $parent, $N, $stderr_factor) = @_;
 
  $N //= parameter_info()->[0]->{'default'};
  ($N > 0) || croak "Kirshenbaum bad N: $N";
 
  $stderr_factor //= parameter_info()->[1]->{'default'};
 
  return $class->SUPER::new
    (parent     => $parent,
     parameters => [ $N, $stderr_factor ],
     arrays     => { middle => [],
                     upper  => [],
                     lower  => [] },
     array_aliases => { values => 'middle' });
}
 
sub proc {
  my ($class_or_self, $N, $stderr_factor) = @_;
  my $ema_proc = App::Chart::Series::Derived::EMA->proc($N);
  my $stderr_proc = App::Chart::Series::Derived::LinRegStderr->proc($N);
 
  return sub {
    my ($value) = @_;
    my $ema = $ema_proc->($value);
    my $stderr = $stderr_proc->($value) * $stderr_factor;
    return ($ema, $ema + $stderr, $ema - $stderr);
  };
}
sub warmup_count {
  my ($self_or_class, $N, $stderr_factor) = @_;
  return max (App::Chart::Series::Derived::EMA->warmup_count($N),
              App::Chart::Series::Derived::LinRegStderr->warmup_count($N));
}
*fill_part = \&App::Chart::Series::Derived::Bollinger::fill_part;
 
1;
__END__
 
# =head1 NAME
#
# App::Chart::Series::Derived::Kirshenbaum -- kirshenbaum bands
#
# =head1 SYNOPSIS
#
#  my $series = $parent->Kirshenbaum($N);
#  my $series = $parent->Kirshenbaum($N, $stderr_factor);
#
# =head1 DESCRIPTION
#
# ...
#
# =head1 SEE ALSO
#
# L<App::Chart::Series>, L<App::Chart::Series::Derived::SMA>
#
# =cut

lib/App/Chart/Series/Derived/LinRegStderr.pm  view on Meta::CPAN

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
 
#     Showing how to calculate the variance in the error amounts (e[i])
#     without calculating a,b parameters.
#
#
#
#               Sum (y - (a+b*x))^2
# stderr = sqrt -------------------
#                       N^2
#
#               Sum ((y - My) - b*x)^2
#        = sqrt ----------------------     where My = Mean(Y)
#                       N^2
#
#               Sum (y - My)^2 - 2*My*b*x + b^2*x^2
#        = sqrt -----------------------------------
#                               N^2
#

lib/App/Chart/Series/Derived/LinRegStderr.pm  view on Meta::CPAN

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
sub longname  { __('Linear Regression Stderr') }
sub shortname { __('Linreg Stderr') }
sub manual    { __p('manual-node','Linear Regression Standard Error') }
 
  { type       => 'indicator',
    units      => 'price',
    priority   => -10,
    minimum    => 0,
    parameter_info => [ { name    => __('Days'),
                          key     => 'linregstderr_days',
                          type    => 'integer',
                          minimum => 1,
                          default => 20 } ],
  };
 
sub new {
  my ($class, $parent, $N) = @_;
 
  $N //= parameter_info()->[0]->{'default'};
  ($N > 0) || croak "LinRegStderr bad N: $N";
 
  return $class->SUPER::new
    (parent     => $parent,
     N          => $N,
     parameters => [ $N ],
     arrays     => { values => [] },
     array_aliases => { });
}
*warmup_count = \&App::Chart::Series::Derived::SMA::warmup_count; # $N-1
 
# Return the factor for 1/Variance(X) arising in the stderr formula.  With
# X values -1.5,-0.5,0.5, 1.5 this means
#
#                         1
#      --------------------------------------------
#      n * ((-1.5)^2 + (-0.5)^2 + (0.5)^2 + (1.5)^2)
#
# and the denominator here is (n^4 - n^2)/12.  See devel/ema-omitted.pl for
# checking this.  Same func in RSquared.pm too.
#
sub xfactor {

lib/App/Chart/doc/chart.html  view on Meta::CPAN

2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
<a class="index-entry-id" id="index-Variance-1"></a>
<a class="index-entry-id" id="index-Deviation-1"></a>
<a class="index-entry-id" id="index-Standard-error"></a>
 
<a class="index-entry-id" id="index-Kirshenbaum_002c-Paul"></a>
<p>Kirshenbaum bands are channel lines drawn around an exponential moving average
(see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>).  The channel width is a multiple of the
&ldquo;standard error&rdquo; from a linear regression of a past N days (see <a class="pxref" href="#Linear-Regression">Linear Regression</a>, and the EMA is smoothed using the same N days.
</p>
<p>Kirshenbaum bands are similar to Bollinger bands (see <a class="pxref" href="#Bollinger-Bands">Bollinger Bands</a>),
but with a linear regression standard error (stderr) instead of a standard
deviation (stddev, see <a class="pxref" href="#Standard-Deviation">Standard Deviation</a>).  The difference is that stddev
takes no account of a trend, so the Bollinger channel widens when a trend is
in progress.  But stderr is based on deviation from a fitted sloping line, so
if prices are making steady progress up or down the channel width remains
small.
</p>
<p>The standard error values (ie. the channel width) can be viewed directly as
an indicator too as &ldquo;Linear Regression Stderr&rdquo; (see <a class="pxref" href="#Linear-Regression">Linear Regression</a>).
</p>
 
<hr>
</div>
<div class="section-level-extent" id="Parabolic-SAR">

lib/App/Chart/doc/chart.html  view on Meta::CPAN

4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
(Linear Regression Slope), to show how steep the fitted trend line is.  The
units are price change per day, which is negative for a downward sloping line.
This may or may not be particularly useful so it&rsquo;s under &ldquo;Low Priority&rdquo; in
the indicator lists.
</p>
<a class="index-entry-id" id="index-Standard-error-1"></a>
<a class="anchor" id="Linear-Regression-Standard-Error"></a></div>
<div class="subsection-level-extent" id="Standard-Error">
<h4 class="subsection"><span>11.1.2 Standard Error<a class="copiable-link" href="#Standard-Error"> &para;</a></span></h4>
 
<p>Standard error (stderr) is a statistical measure of how much values differ
from an assumed underlying curve.  It&rsquo;s calculated as the quadratic mean of
the vertical distances from each point to the curve.
</p>
<p>Standard error from a linear regression line <em class="math">y=a+bx</em> is
</p>
<div class="example">
<pre class="example-preformatted">               / (y1 - (a+b*x1))^2 + ... + (yN - (a+b*xN))^2 \
Stderr = sqrt |  -------------------------------------------  |
               \                     N                       /
</pre></div>
 
<p>Notice the numerator is the same SumSquares which was minimized above.
Standard error is similar to standard deviation (see <a class="pxref" href="#Standard-Deviation">Standard Deviation</a>);
but where stddev takes differences from a horizontal line (the <em class="math">Y</em> mean),
stderr here goes from the sloping linear regression line.
</p>
<p>For reference, there&rsquo;s no need to actually calculate the linear regression
<em class="math">a</em> and <em class="math">b</em>, the stderr can be formed directly as
</p>
<div class="example">
<pre class="example-preformatted">               /               Covariance(X,Y)^2 \
Stderr = sqrt |  Variance(Y) - -----------------  |
               \                  Variance(X)    /
</pre></div>
 
<p>where variance and covariance are as follows (and notice they simplify if
<em class="math">X</em> values are chosen to make <em class="math">Mean(X)</em> zero),
</p>

lib/App/Chart/doc/chart.html  view on Meta::CPAN

4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
<p>Standard error from a linear regression like this is used as a channel width
in Kirshenbaum Bands (see <a class="pxref" href="#Kirshenbaum-Bands">Kirshenbaum Bands</a>).  It can also be viewed
directly as an indicator, but this is probably of limited use and for that
reason is under &ldquo;Low Priority&rdquo; in the indicator lists.
</p>
</div>
<div class="subsection-level-extent" id="Additional-Resources-11">
<h4 class="subsection"><span>11.1.3 Additional Resources<a class="copiable-link" href="#Additional-Resources-11"> &para;</a></span></h4>
<ul class="itemize mark-bullet">
stderr without the a,b parameters
</li></ul>
 
 
<hr>
</div>
</div>
<div class="section-level-extent" id="Standard-Deviation">
<div class="nav-panel">
<p>
Next: <a href="#True-Range" accesskey="n" rel="next">True Range</a>, Previous: <a href="#Linear-Regression" accesskey="p" rel="prev">Linear Regression</a>, Up: <a href="#Common-Calculations" accesskey="u" rel="up">Common Calculations</a> &nbsp; [<a h...

t/1-omf.t  view on Meta::CPAN

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
my $wstat = system
  "scrollkeeper-install -v -p $tempdir $omffile >omf.out 2>omf.err";
is ($wstat, 0, 'scrollkeeper-install exit status');
 
# show output only on error, the normal output is only confusing
if ($wstat) {
  require File::Slurp;
  diag "omf.out stdout:";
  diag File::Slurp::read_file('omf.out');
  diag "omf.err stderr:";
  diag File::Slurp::read_file('omf.err');
}
 
# chdir out of directory so File::Temp can remove it
chdir(File::Spec->rootdir);
exit 0;



( run in 3.761 seconds using v1.01-cache-2.11-cpan-26ccb49234f )