Studying R (including xts and quantmod packages). There is my dataset:
str(h2)
‘zoo’ series from 2016-06-15 11:00:00 to 2016-09-15 14:00:00
Data: num [1:928, 1:5] 67842 67486 67603 67465 67457 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "X.OPEN." "X.HIGH." "X.LOW." "X.CLOSE." ...
Index: POSIXct[1:928], format: "2016-06-15 11:00:00" "2016-06-15 12:00:00" "2016-06-15 13:00:00" ...
first(h2, '1 day')
X.OPEN. X.HIGH. X.LOW. X.CLOSE. X.VOL.
2016-06-15 11:00:00 67842 67842 67122 67488 262740
2016-06-15 12:00:00 67486 67610 67420 67603 288875
2016-06-15 13:00:00 67603 67608 67381 67466 323498
2016-06-15 14:00:00 67465 67484 67356 67455 168991
2016-06-15 15:00:00 67457 67460 67289 67361 174965
2016-06-15 16:00:00 67363 67381 67202 67317 195579
2016-06-15 17:00:00 67320 67465 67288 67397 230255
2016-06-15 18:00:00 67397 67436 67084 67099 469379
2016-06-15 19:00:00 67096 67198 66900 67058 264430
2016-06-15 20:00:00 67040 67094 66944 67092 110503
2016-06-15 21:00:00 67092 67158 66877 66992 83041
2016-06-15 22:00:00 66993 67110 66680 66909 386905
2016-06-15 23:00:00 66909 67269 66884 67126 143373
dput(first(h2, '1 day'))
structure(c(67842, 67486, 67603, 67465, 67457, 67363, 67320,
67397, 67096, 67040, 67092, 66993, 66909, 67842, 67610, 67608,
67484, 67460, 67381, 67465, 67436, 67198, 67094, 67158, 67110,
67269, 67122, 67420, 67381, 67356, 67289, 67202, 67288, 67084,
66900, 66944, 66877, 66680, 66884, 67488, 67603, 67466, 67455,
67361, 67317, 67397, 67099, 67058, 67092, 66992, 66909, 67126,
262740, 288875, 323498, 168991, 174965, 195579, 230255, 469379,
264430, 110503, 83041, 386905, 143373), .Dim = c(13L, 5L), .Dimnames = list(
NULL, c("X.OPEN.", "X.HIGH.", "X.LOW.", "X.CLOSE.", "X.VOL."
)), index = structure(c(1465977600, 1465981200, 1465984800,
1465988400, 1465992000, 1465995600, 1465999200, 1466002800, 1466006400,
1466010000, 1466013600, 1466017200, 1466020800), class = c("POSIXct",
"POSIXt"), tzone = ""), class = "zoo")
Can't figure out how to solve, for example, such task - to compare the sign of the difference (X.CLOSE-X.OPEN) at 11:00 and the difference (X.CLOSE(13:00)-X.OPEN(12:00)) on all days included in the sample.
During solving this problem I see 2 items:
1). how access to data at specific time? I.e. how for example get X.OPEN at 12:00 day I choose. I try different combinations (see code below) but no result (only title of dataset)
h2["T11:00:00/12:00:00"]
X.OPEN. X.HIGH. X.LOW. X.CLOSE. X.VOL.
h2["2016-06-15 11:00:00 MSK"]
X.OPEN. X.HIGH. X.LOW. X.CLOSE. X.VOL.
x <- h2["2016-06-15 11:00:00 MSK"] #'zoo' series (without observations)
x
X.OPEN. X.HIGH. X.LOW. X.CLOSE. X.VOL.
h2["T12:00:00.000/T12:00:00.001"]
X.OPEN. X.HIGH. X.LOW. X.CLOSE. X.VOL.
2). Earlier I made similar algorithm in Excel and solve this problem by bruteforce (step by step checking) dataset. But R have vectorial data types and it should be faster and more convenient way to solve this task.