[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NT with MORE THAN 2 CPU's? RAM Disks?



PureBytes Links

Trading Reference Links

On Jan 15,  9:30pm, Ian MacAuslan wrote:
> 
> ps:  I've noticed back-testing my system that makes use of Bollinger
> Bands takes *much* longer to run than my others (that use moving
> averages, channel breaks and the like).  I suspect that Standard
> Deviation calculations, for some reason, are much more processor
> intensive.  This might be a place where AMD Athlon would improve
> performance.

This might be a place where recoding the standard deviation and/or
B-band routine would make sense.  The standard deviation calculation
in one fomulation first takes the average, and then the displacements
from the average and squares them.  The calculation of average
can be sped up, but once the new average is calculated, all the
displacements from that average have to be recalculated.  Another
formulation for standard deviation uses the running sum of the values,
and the running sum of the squared values, and this calculation
can be done in a way that each calculation involves only two
data points.  I haven't checked out the following, but it
illustrates the basic idea:

{
  Function: fast SD

  Faster implementation of standard deviation.  Has to be
  called on each bar.
}
inputs: Price(numericseries), N(numericsimple);
var: sum(0), sumsq(0), j(0), init(false);
if not init then begin
    for j = 0 to (N-1) do begin
        sum = sum + Price[j];
        sumsq = sumsq + Price[j] * Price[j];
    end;
    init = true;
end else begin
    { a new data point - subtract old, add new }
    sum = sum - Price[N] + Price[0];
    sumsq = sumq - (Price[N]*Price[N]) + (Price[0]*Price[0]);
end;
fastsd = Squareroot((sumsq - ((sum * sum) / N)) / (N - 1));

Something else to try, would be to use exponential moving
averages to approximate the moving average and average
squared displacement from the moving average:

{ xbband indicator }
inputs: Price(Close), width(2.0);
vars: ave(0), diff(0), avediffsq(0);
vars: approx_sd(0), lower_band(0), upper_band(0);
ave = xaverage(Price, N);
diff = (price - ave);
avediffsq = xaverage(diff * diff, N);
approx_sd = Squareroot(avediffsq);
upper_band = ma + band_width * approx_sd;
lower_band = ma - band_width * approx_sd;
plot1(ave, "Average");
plot2(lower_band, "Lower_BB");
plot3(upper_band, "Upper_BB");