0

I'm back with my problems about aggregating tick data (R : Tick data adding value when tick data is missing)

I've followed all your advices and it works perfectly. But I've got a problem with the calendar : mu xts object is indexed with a dateTime object that doesn't respect the open and close hours of the SX5E index.

For example : the SX5E index closes at 23:00 but there are still prices after 22:00!

2010-02-08 22:58:59     2624
2010-02-08 22:59:59     2624
2010-02-08 23:00:59     2624
2010-02-08 23:01:59     2624
2010-02-08 23:02:59     2624
2010-02-08 23:03:59     2624
2010-02-08 23:04:59     2624
2010-02-08 23:05:59     2624
2010-02-08 23:06:59     2624
2010-02-08 23:07:59     2624

I guess I can solve the problem by modifiying a little bit the second line of Joshua Ulrich's code : (R : Tick data adding value when tick data is missing)

price_1m <-to.period(price,period="minutes",k=1,OHLC=FALSE)
onemin <- seq(start(price_1m),end(price_1m),by="1 min") 
Price_1m <- na.locf(merge(price_1m, xts(,onemin)))[onemin]

but I don't know how to generate a 1 min equally spaced sequence from 08:00:00 to 23:00:00. (Maybye using seq.POSIXt?) Any idea?

Community
  • 1
  • 1
marino89
  • 899
  • 1
  • 10
  • 16
  • 1
    Ya know. There were TWO answers to your other question that you link to. I feel so small. My answer would split by day before filling in and subsetting by `timespan` (which would be something like `"T08:00:00/T23:00:00"`. If it's not working like you want, maybe play with the `maxgap` argument to `MakeStrictlyRegular` – GSee Aug 02 '12 at 12:19

1 Answers1

3

I believe that all you need to do here is use xts-style time-of-day subsetting. If your xts object is called "Price_1m", then

Price_1m["T08:00:00/T23:00:00"] 

would, for all days, remove all data that is not between those times.

If you want something more general, I'll point you back to my qmao package to look at ?TimeOfDaySubset

You don't have to use my package if you don't want, but it wouldn't hurt you to at least look at the code (which you can browse on the web). If you use qmao::MakeStrictlyRegular you could do the subsetting there instead.

GSee
  • 48,880
  • 13
  • 125
  • 145