help on creating 5 minutes bars
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.