I am new to coding in R and have found myself stuck. My file consists of highfrequency stock index data and it's converted into an xts file. See below (Left column is date and time and right column is intraday return):
2007-01-02 09:00:00 0.000000e+00
2007-01-02 09:01:00 2.670405e-05
2007-01-02 09:02:00 1.387629e-03
2007-01-02 09:03:00 -1.866841e-04
2007-01-02 09:04:00 -3.201110e-04
2007-01-03 09:00:00 0,0000000000
2007-01-03 09:01:00 -1.321929e-04
2007-01-03 09:02:00 -1.586546e-04
2007-01-03 09:03:00 7.665975e-04
2007-01-03 09:04:00 -5.284993e-05
2007-01-03 09:05:00 -2.907246e-04
My data goes over five years and what I want to is subset it by 500 days and then move it forward 30 days in a loop. However, the loop in itself is not needed, but help of how to construct this kind of function would be highly appreciated.
I have used following function, in which my dataset is named "DIRV" that is the sum of intraday returns:
b<-head(DIRV, n=500)
L<-as.Date(index(b)[1])
J<-as.Date(index(b)[500])
V<-IRV["L/J"]
But I get the following error:
Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year, : missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In as_numeric(YYYY) : NAs introduced by coercion 2: In as_numeric(YYYY) : NAs introduced by coercion