-1

I have one time serie where I want to calculate Z-score, but if I applicate Bollinger Band for verification, I get different result. If I understand correctly, from both (Zscore, BB) we should get the same result, in Zscore is result only normalized.

library("TTR")
data <- read.csv(file="ts1.csv",h=F)
data <- as.numeric(unlist(data))
zs <- (data-SMA(data, n=20))/sd(data)
bb <- BBands(data, n = 20, SMA, sd=2) 

par(mfrow = c(2,1))
plot(data, t = "l")
lines(bb[,1], col = 'brown')
lines(bb[,2], col = 'brown')
lines(bb[,3], col = 'brown')
plot(zs, col = "black", t="l")

The result is: enter image description here

Data source: https://www.dropbox.com/s/vpgd4mtm2bvbc9t/ts1.csv?dl=0

Franta
  • 23
  • 2

1 Answers1

0

The solution is: zs <- (data-SMA(data, n=20))/runSD(data, n = 20)

Franta
  • 23
  • 2