PureBytes Links
Trading Reference Links
|
I think Ami uses the population Stdev rather than the
sample Stdev. ie.
function edev(P, pds)
{
mean = EMA(p, pds);
dev = sqrt(EMA(P^2, pds) - mean^2);
return dev;
} if you replace ema with ma, the result is the same as stdev.
Trying to figure out volatility, I had an interesting diversion into
what StDev is doing, and how I might make something more useful.
Since StDev uses a simple moving average in its calculation, you'll
see a laggy bounce effect from sudden price changes. That is the way
it is defined, and that is fine, but not what I wanted. So I swapped
out the MA for EMA, and I like the result.
dan
/* Exponential
Standard Deviation by Daniel LaLiberte liberte@xxxxxxxxxxxxx
Same
calculation as Standard Deviation, but using an EMA instead of MA. The
effect is to smooth out the laggy bounce from sudden changes.
For
comparision, I tried to reproduce the built-in StDev function, and discovered
that it is using a rapid calculation method instead. The RapidStDev function
defined below appears to work just like StDev, although there my be some
rounding errors, or perhaps a different method is actually used. It
would be good for this to be documented.
The standard (non-rapid) form of
the calculation is described at: http://stockcharts.com/education/IndicatorAnalysis/indic_standardDev.h tml Wikipedia
tells all: http://en.wikipedia.org/wiki/Standard_deviation Also
see comparison of different methods for AmiBroker: http://www.purebytes.com/archives/amibroker/2005/msg01812.html
Using
the standard form of the standard deviation, I modified it to use an
exponential moving average instead of the normal MA. This is EStDev. I
also modified RapidStDev to create an expontial form, RapidEStDev.
Curiously, the two functions perform identically, for large enough
n. */
function EStDev(base, n) { // Calculate the simple average
(mean) of the closing price. // Use EMA instead, to de-bounce the
spikes // m = MA(base, n); //
orignial m = EMA(base, n); //
exponential
// subtract the average closing price from the actual closing
price. d = m - base;
// Square each
period's deviation. d2 = d * d;
// Sum
the squared deviations. // Divide that by the number of
periods. // sd2 = MA(d2, n); //
original sd2 = EMA(d2, n); //
exponential
// The StDev is then equal to the square root of that
number. sd =
sqrt(sd2); return sd;
}
function RapidStDev(base,
n) { m = MA(base,
n); return Sqrt( (Sum(base * base, n) - n * m
* m ) / (n - 1) ); }
function RapidEStDev(base,
n) { m = EMA(base,
n); return Sqrt( (n * EMA(base * base, n) - n
* m * m ) / (n - 1) ); }
pds = Param("pds", 200, 2, 500,
1);
// These two are the same: Plot(EStDev(Close, pds), "EStDev",
colorBlack); Plot(RapidEStDev(Close, pds), "RapidEStDev",
colorRed);
// These two are the same: Plot(StDev(Close, pds), "StDev",
colorBlue); Plot(RapidStDev(Close, pds), "RapidStDev",
colorGold);
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
YAHOO! GROUPS LINKS
|