[R-SIG-Finance] Constructing suitable temporal subsamples using zoo and/or xts
Jeffrey Ryan
jeffrey.ryan at lemnica.com
Sat Jan 28 20:13:53 CET 2012
Not entirely sure what you mean by 'rolling' analysis. If you mean
apply by day then this will do the trick:
do.call(rbind, lapply( split(x['T09:30/T16:00'], "days"), function(x)
do_something(x)))
If you mean just filter out the extraneous times you only need:
x['T09:30/T16:00']
Sample code (small, reproducible) is always requested for the sake of
clarity and getting the answer you are expecting from the list. When
asking for help of the list or authors, remember that other's time is
worth more than yours for that small moment.
If that isn't what you are looking for, see above - but whatever you
do don't resort to perl ;-)
Best,
Jeff
On Sat, Jan 28, 2012 at 1:04 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Sat, Jan 28, 2012 at 1:36 PM, Ted Byers <r.ted.byers at gmail.com> wrote:
>> I am managing to confuse myself with what I am seeing in the docs, and
>> results returned by Google, so I hope someone here can provide me a bit of
>> clarity.
>>
>>
>>
>> I am working with tick data, from which I have been constructing an xts
>> object with a datetime field and a price field, from which I then construct
>> one minute OHLC data. I know I have to use zoo's function to interpolate
>> missing data (since there are a few minutes through the data when nothing
>> was traded, even for a high volume futures contract).
>>
>>
>>
>> I want to use rollapply on daily data to apply my analysis to daily data
>> between 9:30AM EST and 4:30PM EST as that is when most of the trading of
>> these contracts happen, but there I sporadic trading of these contracts
>> outside those times which I would like to ignore.
>>
>>
>>
>> I have found rollapply easy to use (and that is why I need zoo's
>> interpolation capability so it doesn't fail because of missing data), and
>> have seen apply.daily.
>>
>>
>>
>> I thus expect I need two functions: 1) to do my analysis (already done and
>> working fine - this returns a data.frame with all the variables I require in
>> my output); 2) a function to invoke rollapply on a daily sample, and which I
>> can pass to apply.daily in order to get results for all the days for which I
>> have data.
>>
>>
>>
>> What I don't know how to do is how to tell rollapply that it is to work only
>> on values with times between my start and end times, for whatever date's
>> data it happens to get, or how to combine the results for each day into a
>> single data.frame or zoo or xts object.
>>
>>
>>
>> I guess my question amounts to how I can do this in R, with the capabilities
>> of zoo and/or xts, or do I have to resort to using a mix of SQL, Perl and R
>> to get it done (i.e. make a driver script in Perl that gets a day's worth of
>> data between the right times from my DB using SQL, and then passes that data
>> to my R script).
>>
>
> See ?window.zoo
>
> or perhaps depending on specifics:
>
> hm <- as.numeric(format(time(z), "%H%M"))
> z[hm >= 930 & hm <= 1600)]
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
> _______________________________________________
> 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
www.esotericR.com
R/Finance 2012: Applied Finance with R
www.RinFinance.com
See you in Chicago!!!!
More information about the R-SIG-Finance
mailing list