[R-SIG-Finance] [R-sig-finance] xts feature

Jeff Ryan jeff.a.ryan at gmail.com
Mon Jan 26 19:37:54 CET 2009


Hi Murali,

Yes grep will coerce the index with as.character.  That method should
always work with xts though... and off the top of my head I can't
think of a (more) efficient way to accomplish this.

And you are correct, the period.apply would calculate the in-period
statistic (mean in this case) for each period, NOT the mean for all
observation with that time-stamp.


Jeff

R/Finance 2009: Applied Finance with R
April 24, 25th Chicago, IL

http://www.quantmod.com/news/  http://www.RinFinance.com

On Mon, Jan 26, 2009 at 12:15 PM,  <Murali.MENON at fortisinvestments.com> wrote:
>
> Hi Jeff,
>
> With that same dataset of Kafkaz's, if we wanted to compute the mean of
> all the 15:30:00 Volume datapoints (there are two here), how would we do
> it? The code you give below will perform the 'mean' operation on all
> data points falling within each hour, but separate them day-by-day, if
> that makes sense.
>
> Would I have to do something like
>
> mean(x[grep("15:30:00", index(x)), "Volume"])
>
> This works with a POSIXct index, but seems to assume that there is a
> character representation for the time index?
>
> Cheers,
> Murali
>
>
> -----Original Message-----
> From: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Jeff Ryan
> Sent: 26 January 2009 17:31
> To: kafkaz
> Cc: r-sig-finance at stat.math.ethz.ch
> Subject: Re: [R-SIG-Finance] [R-sig-finance] xts feature
>
> Hi Kafkaz,
>
> Try something like:
>
> period.apply(Vo(x), endpoints(x, 'hours'), mean)
>
> Useful tools from xts that are of interest:
>
> ?period.apply, ?endpoints, ?to.period
>
> You can also use aggregate, which on xts objects will call the method
> from the zoo package (automatically loaded).
>
> HTH
> Jeff
>
> R/Finance 2009: Applied Finance with R
> April 24, 25th Chicago, IL
>
> http://www.quantmod.com/news/  http://www.RinFinance.com
>
> --
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
>
> ia: insight algorithmics
> www.insightalgo.com
>
> _______________________________________________
> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list