could someone please verify ...
the study defines standard deviation as:
but I think standard deviation of a linear regression would need to take account of the linear regression line itself i.e.
sum the squares of the differences between the raw prices and the linear regression line. divide the sum by number of regression bars. take square root of result.
something like ...
the study defines standard deviation as:
PHP Code:
function StDev() {
var nLength = vLRline_length;
var sumX = 0;
var sumX2 = 0;
var aSource = getValue("Close", 0, -nLength);
if (aSource == null) return;
for (i = 0; i < nLength; ++i) {
sumX += aSource[i];
sumX2 += (aSource[i] * aSource[i])
}
var meanX = (sumX/nLength);
var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX));
return stdev;
}
sum the squares of the differences between the raw prices and the linear regression line. divide the sum by number of regression bars. take square root of result.
something like ...
PHP Code:
for (var x=0; x<length; ++x) {
yDiff = Math.abs(close(-barindex) - ((slope*x) + intercept));
y2Sum += (yDiff * yDiff);
--barindex;
}
stdev = Math.sqrt((y2Sum/LRlength));
Comment