2017年6月22日木曜日

Calculate weekly standard deviation


Calculate weekly standard deviation from the start of 2017.

> w<-c();for(i in seq(0,trunc(length(day_xts$inc["2017"])/7)-1 ,1)){w<-append(w,sd(day_xts$inc["2017"][i*7 + c(1,2,3,4,5,6,7)]))};print(w);plot(w)

 [1] 65.57148 15.34834 29.44486 12.59251 21.51522 17.22816 10.75042 31.44534 25.34054 27.51017 24.53375 28.72779 31.99702 28.58238 22.88168 28.34818 17.07546
[18] 21.53181 42.79352 32.35444 19.64446 25.16895 24.29580 16.39832

for the case of 2016. The year is already finished, then magic number 52-1 is in place. it is ugly but acceptable for me.

> w<-c();for(i in seq(0,51 ,1)){w<-append(w,sd(day_xts$inc["2016"][i*7 + c(1,2,3,4,5,6,7)]))};print(w)

 [1] 48.606780 25.084619 24.538599 11.443443 20.049938 12.266874 20.221394 14.648257 17.941705 17.201883 19.345234 13.740798 30.581663 15.650955 18.997494 35.491783
[17] 19.474036 24.333986 19.550910 28.180540 18.927179 16.340135 14.404034 21.351926 23.831752 20.868066 22.401105 23.999008 20.497387 27.022918 28.678846 22.003247
[33] 29.384965 25.602269 17.305380 25.746937 20.846377 27.993196 22.112268 26.525819 24.013885 29.664794 22.166040 33.642377 21.883893 36.787032 24.006943 26.567076
[49] 20.317715  7.653197 14.893271 21.084863

0 件のコメント: