0

I am trying to get out a specific row (at a particular minute in a day) of a minute xts data. I have tried several things but only one strange thing works.

> last(UpRatio["T10:14:00/T10:15:00"])
                TICK.NYSE.Close
2011-12-23 10:15:00       0.7608696

This also works:

UpRatio[ with(as.POSIXlt(index(UpRatio)), (hour == 10 & min == 15)), ]

                    TICK.NYSE.Close
2011-12-23 10:15:00       0.7608696

If I try to do the most intuitive thing I get nothing while expecting a single row. Why is the code below not working?

> UpRatio["T10:15:00"]
 TICK.NYSE.Close

If I try to do next obvious thing I get the whole xts object:

> UpRatio["10:15:00"]
                TICK.NYSE.Close
2011-12-23 09:30:00       1.0000000
2011-12-23 09:31:00       1.0000000
2011-12-23 09:32:00       1.0000000
2011-12-23 09:33:00       1.0000000
2011-12-23 09:34:00       0.8000000
2011-12-23 09:35:00       0.8333333
2011-12-23 09:36:00       0.8571429
2011-12-23 09:37:00       0.8750000
2011-12-23 09:38:00       0.7777778
2011-12-23 09:39:00       0.8000000
2011-12-23 09:40:00       0.8181818
2011-12-23 09:41:00       0.7500000
2011-12-23 09:42:00       0.6923077
2011-12-23 09:43:00       0.7142857
2011-12-23 09:44:00       0.6666667
2011-12-23 09:45:00       0.6250000
2011-12-23 09:46:00       0.6470588
2011-12-23 09:47:00       0.6666667
2011-12-23 09:48:00       0.6315789
2011-12-23 09:49:00       0.6500000
2011-12-23 09:50:00       0.6666667
2011-12-23 09:51:00       0.6818182
2011-12-23 09:52:00       0.6956522
2011-12-23 09:53:00       0.7083333
2011-12-23 09:54:00       0.7200000
2011-12-23 09:55:00       0.7307692
2011-12-23 09:56:00       0.7407407
2011-12-23 09:57:00       0.7500000
2011-12-23 09:58:00       0.7586207
2011-12-23 09:59:00       0.7666667
2011-12-23 10:00:00       0.7419355
2011-12-23 10:01:00       0.7500000
2011-12-23 10:02:00       0.7575758
2011-12-23 10:03:00       0.7647059
2011-12-23 10:04:00       0.7428571
2011-12-23 10:05:00       0.7500000
2011-12-23 10:06:00       0.7567568
2011-12-23 10:07:00       0.7631579
2011-12-23 10:08:00       0.7692308
2011-12-23 10:09:00       0.7750000
2011-12-23 10:10:00       0.7804878
2011-12-23 10:11:00       0.7857143
2011-12-23 10:12:00       0.7906977
2011-12-23 10:13:00       0.7954545
2011-12-23 10:14:00       0.7777778
2011-12-23 10:15:00       0.7608696
2011-12-23 10:16:00       0.7446809
...

What am I missing here? What I do not understand?

Samo
  • 2,065
  • 20
  • 41
  • Don't know much about xts, but I think the problem is that you're sending a character to do POSIX's job (as you already demonstrated when you converted `character` with `as.POSIXlt`). – Roman Luštrik Dec 26 '11 at 09:16

3 Answers3

2

Time of day subsetting currently only works with a range. You could use UpRatio["T10:14:59.999/T10:15:00"] instead of last(UpRatio["T10:14:00/T10:15:00"]). Also note that this will return the 10:15 time for every day in your object.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
0

If you use the full datestamp then it works as your intuition expected:

UpRatio["2011-12-23 10:15:00"]

If you wanted 10:15:00 bars from all days, this is a bit shorter (and clearer) than your POSIXlt version:

UpRatio[grepl('10:15:00',index(UpRatio)]
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
0

Or, hack the source. E.g. just after this block:

if(length(i) == 1 && !identical(integer(),grep("^T.*?/T",i[1]))) { ... }

you could write (untested):

else if(length(i) == 1 && !identical(integer(),grep("^T.*?",i[1]))) {
    i <- gsub("T|:","",i)
    i <- .makeISO8601T(x, i[1])
}

Then you have to write makeISO8601T(); this will be similar to (simpler than) the makeISO8601TT() function found at the end of parse8601.T (I made this community wiki in case someone else wants to add the full patch.)

Darren Cook
  • 27,837
  • 13
  • 117
  • 217