[R-SIG-Finance] Selecting a time range from an XTS series?

Jeff Ryan jeff.a.ryan at gmail.com
Wed Sep 22 17:25:42 CEST 2010


Ulrich,

# create a time sequence from the beginning of 2010 to the 3rd, by hours
# Note that the level of granularity is determined by the maximum precision
# specified of both sides.  Here it is to the hour level - 65 hours in
the example:

x <- timeBasedSeq('2010/2010-01-03 15')

head(x)
[1] "2010-01-01 00:00:00 CST" "2010-01-01 01:00:00 CST"
[3] "2010-01-01 02:00:00 CST" "2010-01-01 03:00:00 CST"
[5] "2010-01-01 04:00:00 CST" "2010-01-01 05:00:00 CST"


xts(1:length(x),x)['T08:00:00/T10:00:00']
                    [,1]
2010-01-01 08:00:00    9
2010-01-01 09:00:00   10
2010-01-01 10:00:00   11
2010-01-02 08:00:00   33
2010-01-02 09:00:00   34
2010-01-02 10:00:00   35
2010-01-03 08:00:00   57
2010-01-03 09:00:00   58
2010-01-03 10:00:00   59

I'll add some examples into the documentation of ?.parseISO8601.  In
general, the actual ISO8601 standard is the place to look first, as
xts implements most of the subsetting functionality defined there.

Best,
Jeff


On Wed, Sep 22, 2010 at 10:10 AM, Ulrich Staudinger
<ustaudinger at gmail.com> wrote:
> Hi there,
>
> I am looking for a way to fetch a specific time range (not a date range)
> from an XTS object (a price series).
>
> As input, I have an xts object that looks roughly like this:
>
> ..........
> 2010-08-20 19:54:49   2537.5
> 2010-08-20 19:55:58   2550.0
> 2010-08-20 19:58:59   2587.5
> 2010-08-20 19:59:42   2675.0
> 2010-08-20 20:02:50   2675.0
> 2010-08-20 20:03:50   2675.0
> 2010-08-20 20:06:59   2675.0
> 2010-08-20 20:07:59   2675.0
> 2010-08-20 20:08:59   2687.5
> 2010-08-20 20:09:57   2750.0
> 2010-08-20 20:10:35   2750.0
> 2010-08-20 20:11:59   2750.0
> 2010-08-20 20:12:58   2750.0
> 2010-08-20 20:13:49   2812.5
> ........
>
>
> I would like to know if there is a way to fetch something like ****-**-**
> **:10:00 to ****-**-** **:20:00. Meaning, over the whole data set, all
> information between 10th and 20th minute.
> So, I would expect something like this:
>
> ....
> 2010-08-19 23:10:01     123
> 2010-08-19 23:19:01     123
> 2010-08-19 23:20:01     123
> 2010-08-20 00:10:01     123
> 2010-08-19 00:11:01     123
> 2010-08-19 00:20:01     123
> 2010-08-19 01:10:01     123
> ...
>
> Is such a function available?
>
> Thanks,
> Ulrich
>
> --
> Ulrich Staudinger
> ustaudinger at activequant.org
> http://www.activequant.org
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch 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.
>



-- 
Jeffrey Ryan
jeff.a.ryan at gmail.com



More information about the R-SIG-Finance mailing list