1

I have a sample (returns of some stock, 2371 observations) and I want to calculate the standard deviation for a moving horizon of 250 days. That is:

  • calculate sd1 from day 1 to day 250
  • calculate sd2 from day 2 to day 251, etc.

I wrote the following simple code in R. It works until the 1520th repetition. After that, the matrix Val is filled with NA. Any ideas please?

SampleSize = length(returns)

Val = matrix(0, nrow=2121, ncol=1)

for (i in 0:2120) {

Val[i+1,1] =  sd(returns[1+i:250+i]) }
えるまる
  • 2,409
  • 3
  • 24
  • 44
shaun
  • 11
  • 2

0 Answers0