App-Chart
view release on metacpan or search on metacpan
565758596061626364656667686970717273747576
# 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
226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284@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
482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868called 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
488648874888488948904891489248934894489548964897489848994900490149024903490449054906Standard error from a linear regression like this is used as a channel width
in Kirshenbaum Bands (
@pxref
{Kirshenbaum Bands}). It can also be viewed
reason is under ``Low Priority
''
in the indicator lists.
@subsection
Additional Resources
@itemize
@item
@uref
{http://mathworld.wolfram.com/LeastSquaresFitting.html} -- on calculating
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
697071727374757677787980818283848586878889binmode
(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
33343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109sub
manual { __p(
'manual-node'
,
'Kirshenbaum Bands'
) }
use
constant
{
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
262728293031323334353637383940414243444546# 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
60616263646566676869707172737475767778798081828384858687888990919293949596979899100101sub
longname { __(
'Linear Regression Stderr'
) }
sub
shortname { __(
'Linreg Stderr'
) }
sub
manual { __p(
'manual-node'
,
'Linear Regression Standard Error'
) }
use
constant
{
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
210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129<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
447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513(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"
>
¶
;</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
451945204521452245234524452545264527452845294530453145324533453445354536453745384539<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
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"
>
¶
;</a></span></h4>
<ul class=
"itemize mark-bullet"
>
<li><a class=
"uref"
href=
"http://mathworld.wolfram.com/LeastSquaresFitting.html"
>http://mathworld.wolfram.com/LeastSquaresFitting.html</a>
&ndash
; on calculating
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>
 
; [<a h...
4849505152535455565758596061626364my
$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
) {
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 )