I believe there are two reasons why your code doesn't work 

1. You should replace

sd(Close[i]:Close[(i-3)])

with 

sd(Close[(i-3):i]).

This will ensure you select the appropriate obsevations to feed in the sd
function.

2. Per Ray's point above, you need to output the calculated value of sd for
each value of the loop

The code I supplied previously should work for you. 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-do-a-moving-window-on-standard-deviation-tp3247566p3247754.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to