App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/doc/chart.html view on Meta::CPAN
<p>An N-day range midpoint like the tenkan, kijun and cloud lines is also
available separately as “Range Midpoint” if you want to experiment. It’s
under “Low Priority” in the averages list.
</p>
<hr>
</div>
</div>
<div class="section-level-extent" id="Keltner-Channel">
<div class="nav-panel">
<p>
Next: <a href="#Kirshenbaum-Bands" accesskey="n" rel="next">Kirshenbaum Bands</a>, Previous: <a href="#Ichimoku-Kinko-Hyo" accesskey="p" rel="prev">Ichimoku Kinko Hyo</a>, Up: <a href="#Channels-and-Boxes" accesskey="u" rel="up">Channels and Boxes</a...
</div>
<h3 class="section" id="Keltner-Channel-1"><span>9.5 Keltner Channel<a class="copiable-link" href="#Keltner-Channel-1"> ¶</a></span></h3>
<a class="index-entry-id" id="index-Keltner-channel"></a>
<a class="index-entry-id" id="index-Channel_002c-Keltner"></a>
<a class="index-entry-id" id="index-Keltner_002c-Chester-W_002e"></a>
<p>The Keltner channel is an N-day simple moving average (see <a class="pxref" href="#Simple-Moving-Average">Simple Moving Average</a>) of “typical price” (which is (high+low+close)/3), and bands drawn
above and below that at a distance which is the simple moving average of daily
ranges (high to low) in the period.
</p>
<a class="index-entry-id" id="index-Ten_002dday-moving-average-trading-rule"></a>
<p>This indicator was described by Chester W. Keltner in his 1960 book <i class="i">How
To Make Money in Commodities</i>, and those who learnt of it from him apparently
gave it the name Keltner Channel. Keltner himself called it the “Ten-Day
Moving Average Trading Rule” and never claimed any originality for the idea
– it may have come from grain traders in the 1930s, or even earlier.
</p>
<p>The idea is that closes outside the channel suggest strong bullish (or strong
bearish) sentiment and can be bought (or sold). The 10-day period is a
parameter in Chart.
</p>
<p>The channel bands need daily high/low data, so when that’s not available (a
few indices for instance) they can’t be drawn. The centre line is still shown
(it ends up as just a simple moving average of the closes).
</p>
<hr>
</div>
<div class="section-level-extent" id="Kirshenbaum-Bands">
<div class="nav-panel">
<p>
Next: <a href="#Parabolic-SAR" accesskey="n" rel="next">Parabolic SAR</a>, Previous: <a href="#Keltner-Channel" accesskey="p" rel="prev">Keltner Channel</a>, Up: <a href="#Channels-and-Boxes" accesskey="u" rel="up">Channels and Boxes</a> [<a h...
</div>
<h3 class="section" id="Kirshenbaum-Bands-1"><span>9.6 Kirshenbaum Bands<a class="copiable-link" href="#Kirshenbaum-Bands-1"> ¶</a></span></h3>
<a class="index-entry-id" id="index-Kirshenbaum-bands"></a>
<a class="index-entry-id" id="index-Average-2"></a>
<a class="index-entry-id" id="index-Moving-average-1"></a>
<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
“standard error” 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 “Linear Regression Stderr” (see <a class="pxref" href="#Linear-Regression">Linear Regression</a>).
</p>
<hr>
</div>
<div class="section-level-extent" id="Parabolic-SAR">
<div class="nav-panel">
<p>
Previous: <a href="#Kirshenbaum-Bands" accesskey="p" rel="prev">Kirshenbaum Bands</a>, Up: <a href="#Channels-and-Boxes" accesskey="u" rel="up">Channels and Boxes</a> [<a href="#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<h3 class="section" id="Parabolic-SAR-1"><span>9.7 Parabolic SAR<a class="copiable-link" href="#Parabolic-SAR-1"> ¶</a></span></h3>
<a class="index-entry-id" id="index-Parabolic-SAR"></a>
<a class="index-entry-id" id="index-Stop-and-reverse_002c-parabolic"></a>
<a class="index-entry-id" id="index-Wilder_002c-J_002e-Welles-1"></a>
<p>Parabolic stop and reverse (SAR) by J. Welles Wilder is a trend following
system which establishes a trailing stop that’s progressively advanced as a
price move continues. If penetrated then one’s position short or long is
reversed and a new stop established for the move in the opposite direction.
</p>
<p>The stop is calculated as follows. For an upward move, the initial SAR is the
lowest low made in the preceding down movement. From there an extreme high of
the current move is maintained and the stop advances towards that by a
fraction called the “acceleration factor”.
</p>
<div class="example">
<pre class="example-preformatted">SAR = SAR[prev] + accel * (extreme - SAR[prev])
</pre></div>
<p>The initial acceleration factor is 0.02, and each time a new extreme is made,
ie. a new high, it’s increased by adding 0.02, up to a maximum of 0.2. (Those
values are parameters in Chart.) The effect is to move the stop up faster in
a strong move making successive new highs.
</p>
<p>If the SAR for a given day is penetrated by any part of that day’s trading
range then it’s a signal to reverse one’s position and the SAR becomes a
trailing stop for a short. The calculation for that is the same, using the
previous extreme high as the initial stop and maintaining a low to step
towards. Reversals can be seen in the graph when the stop mark switches from
above to below the prices, or back.
</p>
<p>This approach is only suited to trending markets. If prices are chopping back
and forward in a ranging market then a lot of whipsaw reversals are generated.
At each reversal the new stop point can be quite a distance from the current
prices, ie. one’s entry point, making those whipsaws expensive. Wilder
believed markets trend only about 30% of the time. His ADX
(see <a class="pxref" href="#Directional-Movement-Index">Directional Movement Index</a>) is one way to identify such conditions.
</p>
<p>In Chart the default is not to adjust for dividend payments in the display or
in indicator calculations. If price falls on ex-dividend dates are causing
unwarranted SAR reversals you can turn on the adjustment option in the view
style (see <a class="pxref" href="#View-Style">View Style</a>). (Assuming the data source provides dividend
information.)
</p>
<hr>
lib/App/Chart/doc/chart.html view on Meta::CPAN
<p>The “least squares” or “linear regression” algorithm produces a best
fitting straight line through the middle of a set of N data points
<em class="math">x1,y1,
..., xN,yN</em>. In Chart this means a set of prices Y, and dates X
(with non-trading days collapsed out).
</p>
<p>For a possible fitted line <em class="math">L(X)= a + b*X</em>, the vertical distance
from the line to each point is squared, and a total deviation formed.
</p>
<div class="example">
<pre class="example-preformatted">SumSquares = (y1 - L(x1))^2 + ... + (yN - L(xN))^2
</pre></div>
<p>The line parameters <em class="math">a</em> and <em class="math">b</em> are then chosen to make SumSquares
as small as possible (hence the name “least squares”), and there’s just one
line with that smallest SumSquares. The calculation is made easier if the X
coordinates are shifted so that <em class="math">Mean(X)=0</em>. With that the formulas for
<em class="math">a</em> and <em class="math">b</em> are
</p>
<div class="example">
<pre class="example-preformatted"> y1 + ... + yN
a = Mean Y = -------------
N
x1*y1 + ... + xN*yN
b = -------------------
x1^2 + ... xN^2
</pre></div>
<p>A least squares fit is “best” under certain mathematical assumptions:
basically that the data points were a straight line to which normally
distributed random amounts (positive or negative) have been added. Of course
an underlying straight line is unlikely in market price data, or in economics
generally, and in particular any cyclical component invalidates the
assumptions. Even so the algorithm is quite widely used because it offers an
objective basis for fitting a line.
</p>
<a class="index-entry-id" id="index-Linear-regression-slope-indicator"></a>
<a class="index-entry-id" id="index-Regression-coefficient"></a>
<a class="index-entry-id" id="index-Coefficient_002c-regression"></a>
<a class="anchor" id="Linear-Regression-Slope"></a><ul class="mini-toc">
<li><a href="#Slope" accesskey="1">Slope</a></li>
<li><a href="#Standard-Error" accesskey="2">Standard Error</a></li>
<li><a href="#Additional-Resources-11" accesskey="3">Additional Resources</a></li>
</ul>
<div class="subsection-level-extent" id="Slope">
<h4 class="subsection"><span>11.1.1 Slope<a class="copiable-link" href="#Slope"> ¶</a></span></h4>
<p>The slope of the linear regression line, the <em class="math">b</em> above, is sometimes
called the <em class="dfn">regression coefficient</em>. 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.
</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’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’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>
<div class="example">
<pre class="example-preformatted">Covariance X,Y = Mean (X*Y) - (Mean X) * (Mean Y)
Variance X = Mean(X^2) - (Mean X)^2
</pre></div>
<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 “Low Priority” 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> – 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...
</div>
<h3 class="section" id="Standard-Deviation-1"><span>11.2 Standard Deviation<a class="copiable-link" href="#Standard-Deviation-1"> ¶</a></span></h3>
<a class="index-entry-id" id="index-Standard-deviation-1"></a>
<a class="index-entry-id" id="index-Stddev"></a>
<p>Standard deviation (stddev) is a statistical measure of how much the values in
a data set deviate from their average (mean). The stddev of a past N days is
used in the calculation of Bollinger bands (see <a class="pxref" href="#Bollinger-Bands">Bollinger Bands</a>) and VIDYA
and <a class="ref" href="#Variable-Index-Dynamic-Average">Variable Index Dynamic Average</a>).
</p>
<p>The raw stddev values can be shown in Chart as an indicator, to see what goes
into those calculations. The values have little direct use though, and for
that reason stddev is under “Low Priority” in the indicator lists.
</p>
<a class="index-entry-id" id="index-Quadratic-mean-1"></a>
<a class="index-entry-id" id="index-Mean_002c-quadratic-1"></a>
<p>For reference, the formula on prices p1 to pN is as follows. Each
<em class="math">p[i]-m</em> is the distance from the mean <em class="math">m</em>, and those distances
are averaged with a quadratic mean.
</p>
<div class="example">
<pre class="example-preformatted"> / (p1-m)^2 + (p2-m)^2 + ... + (pN-m)^2 \
Stddev = sqrt ( ------------------------------------ )
\ N /
</pre></div>
<p>where <em class="math">m</em> is the arithmetic mean
</p>
<div class="example">
<pre class="example-preformatted"> p1 + p2 + ... + pN
m = ------------------
N
</pre></div>
<p>Also, for reference, the formula can be rearranged to the following form,
“sum of the squares minus square of the sums”. This is what Chart uses,
because a new term can be shifted into the sums without recalculating all N
terms.
</p>
<div class="example">
<pre class="example-preformatted"> / p1^2 + p2^2 + ... + pN^2 (p1 + p2 + ... + pN)^2 \
Stddev = sqrt ( ------------------------ - ---------------------- )
\ N N^2 /
</pre></div>
<hr>
</div>
<div class="section-level-extent" id="True-Range">
<div class="nav-panel">
( run in 0.523 second using v1.01-cache-2.11-cpan-39bf76dae61 )