An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120508/35d02fa6/attachment.pl>
Dividing tick-data into intervalls
3 messages · osvald wiklander, Milan Bouchet-Valat, R. Michael Weylandt
Le mardi 08 mai 2012 ? 10:44 +0200, osvald wiklander a ?crit :
Hi everybody, I am sorry that I am kind of spamming this forum, but I
have searched for some input everywhere and cant really find a nice
solution for my problem.
Data looks like:
price
2011-11-01 08:00:00 0.000000000
2011-11-01 08:00:00 0.000000000
2011-11-01 08:02:00 0.000000000
2011-11-01 08:03:00 -0.017033339
2011-11-01 08:13:00 0.000690001
2011-11-01 08:24:00 0.000658411
2011-11-01 08:29:00 0.000000000
2011-11-01 08:29:00 0.000000000
2011-11-01 08:29:00 0.000000000
2011-11-01 08:29:00 0.000000000
2011-11-01 08:29:00 0.002166062
2011-11-01 08:44:00 0.000000000
2011-11-01 08:44:00 -0.002166062
2011-11-01 08:44:00 0.004321374
2011-11-01 10:36:00 0.010618976
2011-11-01 15:59:00 0.002092990
So the price column in fact shows the difference in the price of the
equity. It is about 100 days.
I want to be able to convert this data to regurly spaced intervals,
like every fifth minute the previous tick is returned.
So, for example I want that the new time serie should look like:
price
2011-11-01 08:00:00 0.000000000
2011-11-01 08:05:00 -0.017033339
2011-11-01 08:10:00 -0.017033339
2011-11-01 08:15:00 0.000690001
2011-11-01 08:20:00 0.000000000
2011-11-01 08:25:00 0.000658411
2011-11-01 08:30:00 0.002166062
And so on for the 100 days. And the I want to do this for ten minutes,
30 minutes etc.
Earlier I have tried with aggregatePrice() (in the RTAQ package)
combined with a for() loop. However this didnt work so well.
I assume it exist some easy way to do this? However, as I said, I have
searched for a solution without any luck.
So, what approach should I have? Have any of you done something like
this before?
I think you should create a zoo object (from package zoo) from your data, and use aggregate() on it (see ?aggregate.zoo). My two cents
Are you the oswi who just asked a very similar question? Regardless, as Josh said, the high-performance way to do this is to use the specialty C code available through the xts package and the to.period() functions, specifically to.minutes5 Michael
On Tue, May 8, 2012 at 8:48 AM, Milan Bouchet-Valat <nalimilan at club.fr> wrote:
Le mardi 08 mai 2012 ? 10:44 +0200, osvald wiklander a ?crit :
Hi everybody, I am sorry that I am kind of spamming this forum, but I have searched for some input everywhere and cant really find a nice solution for my problem. Data looks like: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?price 2011-11-01 08:00:00 ?0.000000000 2011-11-01 08:00:00 ?0.000000000 2011-11-01 08:02:00 ?0.000000000 2011-11-01 08:03:00 -0.017033339 2011-11-01 08:13:00 ?0.000690001 2011-11-01 08:24:00 ?0.000658411 2011-11-01 08:29:00 ?0.000000000 2011-11-01 08:29:00 ?0.000000000 2011-11-01 08:29:00 ?0.000000000 2011-11-01 08:29:00 ?0.000000000 2011-11-01 08:29:00 ?0.002166062 2011-11-01 08:44:00 ?0.000000000 2011-11-01 08:44:00 ?-0.002166062 2011-11-01 08:44:00 ?0.004321374 2011-11-01 10:36:00 ?0.010618976 2011-11-01 15:59:00 ?0.002092990 So the price column in fact shows the difference in the price of the equity. It is about 100 days. I want to be able to convert this data to regurly spaced intervals, like every fifth minute the previous tick is returned. So, for example I want that the new time serie should look like: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?price 2011-11-01 08:00:00 ?0.000000000 2011-11-01 08:05:00 -0.017033339 2011-11-01 08:10:00 -0.017033339 2011-11-01 08:15:00 ?0.000690001 2011-11-01 08:20:00 ?0.000000000 2011-11-01 08:25:00 ?0.000658411 2011-11-01 08:30:00 ?0.002166062 And so on for the 100 days. And the I want to do this for ten minutes, 30 minutes etc. Earlier I have tried with aggregatePrice() (in the RTAQ package) combined with a for() loop. However this didnt work so well. I assume it exist some easy way to do this? However, as I said, I have searched for a solution without any luck. So, what approach should I have? Have any of you done something like this before?
I think you should create a zoo object (from package zoo) from your data, and use aggregate() on it (see ?aggregate.zoo). My two cents
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.