Statistical function “standard deviation” of a time series N of selected price.
Syntax:
1 |
STD[N](price) |
Calculation :
STD = SQUAREROOT[(summation(from d = 1 to n)(Close-Moving average on n days)²]
Interpretation :
Standard deviation measures the volatility of prices.
It is often used in relation to some indicators. For example the Bollinger bands are calculated from an arithmetic moving average. To plot an upper and lower band, add and substract 2 * (std deviation) as default parameters.
Example:
1 2 3 4 |
myseries = range statisticaldeviation = STD[10](myseries) RETURN statisticaldeviation |
Hello, the defaul function STD in Prorealtime it is in truth like =STDEV.P in Excel: this formula is not suitable for financial analysis because assumes that its arguments are the entire population. We need the code to replicate =STDEV.S because financial data represent a sample of the population. I tried to change the formula you gave to get STDEV.S, but Prorealtime does not even accept what you wrote, figure the rest…
The difference between these 2 Excel formulas is the sample size you take to calculate the standard deviation. A ‘sample’ or the entire population is the same in our case, because the data array is populated within the last N periods. I also notice that Office support say : “For large sample sizes, STDEV.S and STDEV.P return approximately equal values”, which make sense since the population taken in their formulas is the same unlike 1 unit.
Hi Nicolas,
I think the formula has an error, it should be:
STD = SQUAREROOT[((summation(from d = 1 to n)(Close-Moving average on n days)² / n)]
the formula in PRT code just in case anyone needs it is:
// code to obtain the same result as std[20](close)
sum=0
for candle = 0 to 19
sum=sum+square(close[candle]-average[20](close))
next
sum=SQRT(sum/20)
return sum
It takes ages to calculate for a big sample, so I would recommend using the stdev() function from PRT.
Rgds
> It takes ages to calculate for a big sample, so I would recommend using the stdev() function from PRT.
It is because you have to get the average function out of the loop. You calculate the same average uselessly for each candle. You should write:
// code to obtain the same result as std[20](close)
sum=0
average20 = average[20](close)
for candle = 0 to 19
sum=sum+square(close[candle]-average20)
next
sum=SQRT(sum/20)