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

Re: How to calculate STDev?



PureBytes Links

Trading Reference Links

Daniel Posmik wrote:
> IŽd like to calculate the StDev of the Profits directly in the
> systemcode and export it to excel.  Does anyone know how to
> calculate it? 

In pseudocode:
	Xmean = mean value, via your favorite method
	for n = 0 to N-1
	  Sumsq = Sumsq + (X[n] - Xmean) * (X[n] - Xmean)
	Var = Sumsq / (N-1)
	Standard Deviation = squareroot(Var)

That is, sum the squares of the differences of your samples from
the mean of the series, divide by N-1, and take the square root.

As I recall, Omega's function uses (N) in the divisor, not (N-1).
Press et al in Numerical Recipes in C say: "There is a long story
about why the denominator is N-1 instead of N.  If you have never heard
that story, you may consult any good statistics text.  Here we will
be content to note that the N-1 *should* be changed to N if you are
ever in the situation of measuring the variance of a distribution
whose mean is known a priori rather than being estimated from the
data.  (We might also comment that if the difference between N and
N-1 ever matters to you, then you are probably up to no good anyway...)"

Cheers,

Jim