Skip to content
Back to formatted view

Raw Message

Message-ID: <BANLkTi=Wig9OKxz2peibEUNRmtKyWT+osg@mail.gmail.com>
Date: 2011-05-06T01:54:09Z
From: Robert A'gata
Subject: Aggregating time series to every 30sec
In-Reply-To: <BANLkTinPen35vcvkgDmzs49+MM8X++EAZw@mail.gmail.com>

Thank you so much Jeff! This is exactly what I'm looking for.

On Thu, May 5, 2011 at 9:50 PM, Jeffrey Ryan <jeffrey.ryan at lemnica.com> wrote:
> Something like this should work:
> r.xts <- read.table(textConnection("
> 2011-05-05 09:30:04.929 0.3264757
> 2011-05-05 09:30:14.907 0.0934498
> 2011-05-05 09:30:19.917 0.8956367
> 2011-05-05 09:30:35.114 1.6632110
> 2011-05-05 09:30:45.193 1.1666715
> 2011-05-05 09:31:12.417 0.2861861"))
> r.xts
> ?? ? ? ? ?V1 ? ? ? ? ? V2 ? ? ? ?V3
> 1 2011-05-05 09:30:04.929 0.3264757
> 2 2011-05-05 09:30:14.907 0.0934498
> 3 2011-05-05 09:30:19.917 0.8956367
> 4 2011-05-05 09:30:35.114 1.6632110
> 5 2011-05-05 09:30:45.193 1.1666715
> 6 2011-05-05 09:31:12.417 0.2861861
> r.xts <- xts(r.xts$V3, as.POSIXct(paste(r.xts$V1,r.xts$V2)))
> r.xts
> ?? ? ? ? ? ? ? ? ? ? ? ? [,1]
> 2011-05-05 09:30:04 0.3264757
> 2011-05-05 09:30:14 0.0934498
> 2011-05-05 09:30:19 0.8956367
> 2011-05-05 09:30:35 1.6632110
> 2011-05-05 09:30:45 1.1666715
> 2011-05-05 09:31:12 0.2861861
> align.time(period.sum(r.xts,endpoints(r.xts,'secs',k=30)),30)
> ?? ? ? ? ? ? ? ? ? ? ? ? [,1]
> 2011-05-05 09:30:30 1.3155622
> 2011-05-05 09:31:00 2.8298825
> 2011-05-05 09:31:30 0.2861861
> ?endpoints to find the 30m endpoints in time
> ?period.sum (or period.apply) to sum up by period
> ?align.time to fix/round the times to something a little more even
> HTH
> Jeff
> On Thu, May 5, 2011 at 7:47 PM, Robert A'gata <rhelpacc at gmail.com> wrote:
>>
>> Hi,
>>
>> I have an irregular return time series that looks like below:
>>
>> > head(r.xts)
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? [,1]
>> 2011-05-05 09:30:04.929 0.3264757
>> 2011-05-05 09:30:14.907 0.0934498
>> 2011-05-05 09:30:19.917 0.8956367
>> 2011-05-05 09:30:35.114 1.6632110
>> 2011-05-05 09:30:45.193 1.1666715
>> 2011-05-05 09:31:12.417 0.2861861
>>
>> I'd like to sum them for every 30-second bucket such that the output
>> looks like below. The key is that I want to aggregate every 30 seconds
>> by clock time NOT 30 seconds starting from my first observation time
>> stamp. rollapply does not satisfy my objective as it takes number of
>> rows instead. to.period function doesn't seem to let me specify that I
>> want to start at 09:30 and sum returns every 30 seconds. I'm wondering
>> if there's any tool that I can achieve this?
>>
>> 2011-05-05 09:30:00 ? 1.316
>> 2011-05-05 09:30:30 ? ...
>> 2011-05-05 09:31:00 ? ...
>>
>> Thank you in advance.
>>
>> Cheers,
>>
>> Robert
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org 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
> jeffrey.ryan at lemnica.com
>
> www.lemnica.com
>
> R/Finance 2011 April 29th and 30th in Chicago | www.RinFinance.com
>
>