1

I'm using R to aggregate tick data and I have the following function which works well to aggregate the data to the minute but now I want to expound on that and aggregate to 5, 10, 15min. How can I do that?

SPY <- aggregate(as.numeric(SPY$PRICE), list(min = cut(index(SPY), breaks="min")), mean)
GSee
  • 48,880
  • 13
  • 125
  • 145
postelrich
  • 3,274
  • 5
  • 38
  • 65

1 Answers1

3

Since you've tagged your question with the xts tag...

You can use period.apply for this. The following will give you the mean of every 5 minutes:

period.apply(SPY$PRICE, endpoints(SPY, "minutes", 5), mean)
GSee
  • 48,880
  • 13
  • 125
  • 145