我的任务是在22天内绘制一个时间序列的波动率,大约有500 000个元素。我想绘制不同尺度的波动率,即白天,3小时,1小时,20分钟,1分钟等,但我也希望这些重叠。例如,对于1小时的比例,我希望它输出波动率为10 am-11am,10.30-11.30,11-12等。
我可以在循环之外完成所有操作,但这需要更长的时间。我知道它可以更有效地完成,但是我发现更多列表中的列表内的data.frames
目前很难理解。
这是我可重复的例子,我希望它足够
x<-rnorm(6000,0,1)
price<- cumsum(x) # this represents stock tick data
day1<-sort( runif(3000,0,6) , decreasing = FALSE)+10 #generate random ordered time stamps between 10:00-16:00 for each trade event
day2<-sort( runif(1000,0,6) , decreasing = FALSE)+10 # only 1000 trade events on this day, hence 1000 timestamps
day3<-sort( runif(2000,0,6) , decreasing = FALSE)+10 # (my actual real world data spans 28 days)
time<-c(day1,day2,day3)
date<-c( rep(20110925L,3000) , rep(20110930L,1000) , rep(20110931L, 2000) ) # the 3 dates are 25/9/2011, 30/9/2011, 31/9/2011
mydata<-data.frame( cbind(date,time,price) )
# I would like to create one single loop to graph the volitilty over different periods using 1 minute, 20 min, 1 hour and whole day blocks.
# I would also like to implement it so that it examines the inbetween block-eg. for 20 minute blocks: it looks at 10:00-10:20, 10:10-10:30,10:20-10:40, etc.
# finally i would like to graph these, but I am really new to R so i'm finding it very difficult. I would love some guidance, tips and tricks