[R-SIG-Finance] xts: xts/xts not an xts? and subsetting on hours across all dates

Gabor Grothendieck ggrothendieck at gmail.com
Sun Oct 11 02:19:05 CEST 2009


1. Its caused by ifelse, not by the division.  Read the Value section
of ?ifelse to better understand how ifelse works.  Its not what your
seem to expect.

2. Modulo time zone problems:

hhmm <- format(time(x), "%H:%M")
x[ hhmm > "09:00" & hhmm < "16:30" ]

Use dput next time to display your data (rather than str) so it can be
reproduced.



On Sat, Oct 10, 2009 at 7:56 PM, zubin <binabina at bellsouth.net> wrote:
> Hello, 2 xts/zoo questions:
>
> 1) experiencing a behavior i can't explain with zoo or xts objects and
> can't seem to rectify
>
> Dividing two zoo or xts objects and I don't get the result as a zoo or
> xts object, i get a number vector with no time index,  pulling my hair
> on this, any recommendations?
>
>  > str(XJZLN.X)
> 'zoo' series from 2009-10-06 09:30:07 to 2009-10-06 15:59:54
>  Data: num [1:2813] 0 0 0 0 0 0 0 0 0 0 ...
>  Index:  POSIXct[1:2813], format: "2009-10-06 09:30:07" "2009-10-06
> 09:30:15" ...
>
>  > str(XJZXN.X)
> 'zoo' series from 2009-10-06 09:30:07 to 2009-10-06 15:59:54
>  Data: num [1:2813] 0 0 0 0 0 0 0 0 0 0 ...
>  Index:  POSIXct[1:2813], format: "2009-10-06 09:30:07" "2009-10-06
> 09:30:15" ...
>
> # fixing the division by zero in the dataset, inserting a constant
>  > dec14callput = ifelse(is.nan(XJZLN.X / XJZXN.X),2.23,XJZLN.X / XJZXN.X)
>
> #however the resulting object is not zoo anymore?
>  > str(dec14callput)
>  num [1:2813] 2.23 2.23 2.23 2.23 2.23 2.23 2.23 2.23 2.23 2.23 ...
>
> ok lets try coercing to a zoo, but now we lose the index?
>
>  > dec14callput = zoo(ifelse(is.nan(XJZLN.X / XJZXN.X),2.23,XJZLN.X /
> XJZXN.X))
>
> 'zoo' series from 1 to 2813
>  Data: num [1:2813] 2.23 2.23 2.23 2.23 2.23 2.23 2.23 2.23 2.23 2.23 ...
>  Index:  int [1:2813] 1 2 3 4 5 6 7 8 9 10 ...
>
>
> 2) How does one subset only hours from an XTS (or zoo) object across
> many days.  I have some ticker data from 10/1/2009 thru 10/8/2009 for
> example.  It is data that contains pre /post session data as well as the
> active trading session.  I want to pull from 9:30 to 4:00 only across
> ALL the dates, in an elegant way.
>
> I have tried window as well as the :: operator for XTS, no luck.
>
> Something like this i was trying for a ZOO object:
>
> tmpfile <- window(XJXLN.X, start = as.POSIXct(("XXXX-XX-XX
> 09:30:00"),end = as.POSIXct("XXXX-XX-XX 16:00:00")))
>
> Any type of wildcard for the dates, so given any date, but only pull
> rows that are between 9:30 and 16:00.
>
>
>
>
>        [[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.
>



More information about the R-SIG-Finance mailing list