An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120924/36e55877/attachment.pl>
help on creating 5 minutes bars
6 messages · R. Michael Weylandt, OpenTrades, Chris de Bleu
On Mon, Sep 24, 2012 at 9:57 AM, Chris de Bleu <blue2bleu at yahoo.fr> wrote:
I would like to convert a 1 minute xts data to 5 minutes bars using "to.minutes5".
library(xts)
N = 20 s = xts(1:N, order.by = seq.POSIXt(ISOdate(2012, 9, 1), by = "min", length = N)) s
[,1] 2012-09-01 12:00:00 1 2012-09-01 12:01:00 2 2012-09-01 12:02:00 3 2012-09-01 12:03:00 4 2012-09-01 12:04:00 5 2012-09-01 12:05:00 6 2012-09-01 12:06:00 7 2012-09-01 12:07:00 8 2012-09-01 12:08:00 9 2012-09-01 12:09:00 10 2012-09-01 12:10:00 11 2012-09-01 12:11:00 12 2012-09-01 12:12:00 13 2012-09-01 12:13:00 14 2012-09-01 12:14:00 15 2012-09-01 12:15:00 16 2012-09-01 12:16:00 17 2012-09-01 12:17:00 18 2012-09-01 12:18:00 19 2012-09-01 12:19:00 20 Warning message: timezone of object (GMT) is different than current timezone ().
to.minutes5(s)
s.Open s.High s.Low s.Close 2012-09-01 12:04:00 1 5 1 5 2012-09-01 12:09:00 6 10 6 10 2012-09-01 12:14:00 11 15 11 15 2012-09-01 12:19:00 16 20 16 20 Warning message: timezone of object (GMT) is different than current timezone (). Why I haven't data at the 5 minutes with these timestamps?
Merely convention: to.period() goes to the _end_ of the unit being aggregated rather than the beginning. This seems reasonable if you consider a time stamp as when something can be known. (I.e., if you marked periods as the beginning, use of "Hi" and "Lo" would introduce a small but non-negligible look ahead into the simulation) Cheers, Michael
2012-09-01 12:00:00
2012-09-01 12:05:00
2012-09-01 12:10:00
2012-09-01 12:15:00
Thank you,
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120924/5645d519/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120924/1291ae76/attachment.pl>
On Mon, Sep 24, 2012 at 1:00 PM, Chris de Bleu <blue2bleu at yahoo.fr> wrote:
Ok, let set N = 21, so the last timestamp is "2012-09-01 12:20:00"
N = 21
s = xts(cbind(1:N, 1:N, 1:N, 1:N), order.by = seq.POSIXt(ISOdate(2012, 9, 1), by = "min", length = N))
colnames(s) = c("Open", "High", "Low", "Close")
s
Open High Low Close 2012-09-01 12:00:00 1 1 1 1 2012-09-01 12:01:00 2 2 2 2 2012-09-01 12:02:00 3 3 3 3 2012-09-01 12:03:00 4 4 4 4 2012-09-01 12:04:00 5 5 5 5 2012-09-01 12:05:00 6 6 6 6 2012-09-01 12:06:00 7 7 7 7 2012-09-01 12:07:00 8 8 8 8 2012-09-01 12:08:00 9 9 9 9 2012-09-01 12:09:00 10 10 10 10 2012-09-01 12:10:00 11 11 11 11 2012-09-01 12:11:00 12 12 12 12 2012-09-01 12:12:00 13 13 13 13 2012-09-01 12:13:00 14 14 14 14 2012-09-01 12:14:00 15 15 15 15 2012-09-01 12:15:00 16 16 16 16 2012-09-01 12:16:00 17 17 17 17 2012-09-01 12:17:00 18 18 18 18 2012-09-01 12:18:00 19 19 19 19 2012-09-01 12:19:00 20 20 20 20 2012-09-01 12:20:00 21 21 21 21
to.minutes5(s)
s.Open s.High s.Low s.Close 2012-09-01 12:04:00 1 5 1 5 2012-09-01 12:09:00 6 10 6 10 2012-09-01 12:14:00 11 15 11 15 2012-09-01 12:19:00 16 20 16 20 2012-09-01 12:20:00 21 21 21 21
align.time(to.minutes5(s), 5*60)
s.Open s.High s.Low s.Close 2012-09-01 12:05:00 1 5 1 5 2012-09-01 12:10:00 6 10 6 10 2012-09-01 12:15:00 11 15 11 15 2012-09-01 12:20:00 16 20 16 20 2012-09-01 12:25:00 21 21 21 21 We remark also that there is a lag in the values.
Is there a question in this? It's consistent with your earlier example: aligning with the end of the grouped period. Michael
[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120924/b8e7ce78/attachment.pl>