Re: [R-SIG-Finance] Aggregating tick-by-tick data to seconds
If you have a column labelled Volume, to.period will sum it: e.g., library(xts) data(sample_matrix) s - as.xts(sample_matrix) s - cbind(s, Volume = round(exp(runif(NROW(s),2,3))*1)) head(s) head(to.weekly(s)) Cheers, Michael On Sat, Sep 15, 2012 at 4:57 PM, Costas Vorlow costas.vor...@gmail.com wrote: Hello, I have the following data (xts) (last two columns refer to up and down volumes). head(test,20) [,1] [,2] [,3] 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 9000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.39 1970 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.380 100 I can use the to.period to aggregate the above data to seconds test.Open test.High test.Low test.Close 2012-09-12 16:30:00144.39144.47 144.37 144.38 2012-09-12 16:31:00144.39144.40 144.33 144.37 2012-09-12 16:32:00144.37144.45 144.37 144.45 2012-09-12 16:33:00144.45144.47 144.42 144.47 but I am not sure how to do this for the volume columns. I would need to retrieve the volume sums per second. Is this functionality built into the xts package? Is there any other function that could be used to do something like that? Thanks best regards, Costas ___ [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Aggregating tick-by-tick data to seconds
You can use `period.apply` (along with `endpoints()`) to apply any function you like over non-overlapping time periods. In this case, you want to sum columns 2 and 3 separately, so use `period.apply()` with `FUN=colSums` on just the 2nd and 3rd columns. period.apply(test[, 2:3], endpoints(test, 'secs'), FUN=colSums) Then you can merge that with the results of `to.period` cbind(to.period(test[, 1], name=test), period.apply(test[, -1], endpoints(test, 'secs'), FUN=colSums)) test.Open test.High test.Low test.Close up down 2012-09-12 16:30:00144.39144.39 144.38 144.38 5903 100 You could also use `period.sum()` on each column separately. HTH, Garrett On Sat, Sep 15, 2012 at 10:57 AM, Costas Vorlow costas.vor...@gmail.com wrote: Hello, I have the following data (xts) (last two columns refer to up and down volumes). head(test,20) [,1] [,2] [,3] 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 9000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.39 1970 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.380 100 I can use the to.period to aggregate the above data to seconds test.Open test.High test.Low test.Close 2012-09-12 16:30:00144.39144.47 144.37 144.38 2012-09-12 16:31:00144.39144.40 144.33 144.37 2012-09-12 16:32:00144.37144.45 144.37 144.45 2012-09-12 16:33:00144.45144.47 144.42 144.47 but I am not sure how to do this for the volume columns. I would need to retrieve the volume sums per second. Is this functionality built into the xts package? Is there any other function that could be used to do something like that? Thanks best regards, Costas ___ [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Aggregating tick-by-tick data to seconds
?period.sum HTH Jeff Jeffrey Ryan|Founder|jeffrey.r...@lemnica.com www.lemnica.com On Sep 15, 2012, at 10:57 AM, Costas Vorlow costas.vor...@gmail.com wrote: Hello, I have the following data (xts) (last two columns refer to up and down volumes). head(test,20) [,1] [,2] [,3] 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 9000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.39 1970 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.380 100 I can use the to.period to aggregate the above data to seconds test.Open test.High test.Low test.Close 2012-09-12 16:30:00144.39144.47 144.37 144.38 2012-09-12 16:31:00144.39144.40 144.33 144.37 2012-09-12 16:32:00144.37144.45 144.37 144.45 2012-09-12 16:33:00144.45144.47 144.42 144.47 but I am not sure how to do this for the volume columns. I would need to retrieve the volume sums per second. Is this functionality built into the xts package? Is there any other function that could be used to do something like that? Thanks best regards, Costas ___ [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.