R indexing of xts with unspaced time interval for HFT (follow up on Display time index hint)
Joshua,
I hope you do not find this to be a layman approach but when I tried to implement your hint how to display only certain time index on my xts object i always get blank figures.
> dput(x)
structure(c("BHP", "BHP", "BHP", "BHP", "BHP", "BHP", "N", "N",
"N", "N", "N", "N", "44560", "44560.0313951103", "44551.6606603345",
"44560", "44560", "44560", "39844", "1072460", "405128", "4911",
"2782", "1632", "44570", "44573.2273632603", "44579.8960524827",
"44577.1033732318", "44579.9904979095", "44574.9768058317", "80",
"13054", "88410", "13785", "5262", "1509", "12", "12", "12",
"12", "12", "12"), .indexCLASS = structure("timeDate", package = "timeDate"),
.indexTZ = "", class = c("xts", "zoo"), i开发者_JAVA百科ndex = structure(c(1306922412,
1306922414, 1306922415, 1306922416, 1306922417, 1306922418), tzone = "",
tclass = structure("timeDate", package = "timeDate")), .Dim = 6:7, .Dimnames =
list(NULL, c("SYMBOL", "EX", "BID", "BIDSIZ", "OFR", "OFRSIZ","MODE")))
> x["T10:00:14/T10:00:17"]
SYMBOL EX BID BIDSIZ OFR OFRSIZ MODE
So I get no values though the values are clearly there, what am I missing?
You don't say how you are creating the xts object, but I think it is a small bug in how xts is creating the object - it is not adding in the TZ from the timeDate object.
Try:
indexTZ(x) <- "GMT"
x['20110601 10:00:14/20110601 10:00:17']
SYMBOL EX BID BIDSIZ OFR
2011-06-01 10:00:14 "BHP" "N" "44560.0313951103" "1072460" "44573.2273632603"
2011-06-01 10:00:15 "BHP" "N" "44551.6606603345" "405128" "44579.8960524827"
2011-06-01 10:00:16 "BHP" "N" "44560" "4911" "44577.1033732318"
2011-06-01 10:00:17 "BHP" "N" "44560" "2782" "44579.9904979095"
OFRSIZ MODE
2011-06-01 10:00:14 "13054" "12"
2011-06-01 10:00:15 "88410" "12"
2011-06-01 10:00:16 "13785" "12"
2011-06-01 10:00:17 "5262" "12"
HTH Jeff
w.r.t. the bug - I'll look into and patch. Thanks.
> x[ with(as.POSIXlt(index(x)), ( sec >= 14)) & with(as.POSIXlt(index(x)), ( sec <= 16) ), ]
SYMBOL EX BID BIDSIZ OFR
2011-06-01 10:00:14 "BHP" "N" "44560.0313951103" "1072460" "44573.2273632603"
2011-06-01 10:00:15 "BHP" "N" "44551.6606603345" "405128" "44579.8960524827"
2011-06-01 10:00:16 "BHP" "N" "44560" "4911" "44577.1033732318"
OFRSIZ MODE
2011-06-01 10:00:14 "13054" "12"
2011-06-01 10:00:15 "88410" "12"
2011-06-01 10:00:16 "13785" "12"
I could not get the form described in ?"[.xts" to work when being used at the seconds-level of specification, but I see that Jeff R has arrived on the scene and demonstrated that the indexTZ(x) <- "GMT"
maneuver (not referenced from any of many the help pages I looked at, is necessary.
精彩评论