[R-SIG-Finance] Filtering dates/times from zoo/xts series

Arun Krishnamoorthy arun.k at bridgei2i.com
Mon Sep 26 11:41:54 CEST 2011


Is there a nice way to aggregate daily data from xts or zoo to a monthly
level?
Example.

new<-getSymbols("INR=X",src="yahoo", auto.assign = FALSE)

returns INR to USD at a daily level as a xts. Is there a nice way to get a
monthly or weekly average & std dev from this data that has O, C, L, H and
volume? Sorry, I may have missed a discussion on this from before.

Thanks,
AK
-----Original Message-----
From: r-sig-finance-bounces at r-project.org
[mailto:r-sig-finance-bounces at r-project.org] On Behalf Of chrisbird
Sent: 26 September 2011 13:54
To: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] Filtering dates/times from zoo/xts series

Ok, I don't know whether I'm just rested after the weekend, but after
struggling to figure this out last week I now seem to have solved it all
this morning.

My solution is as follows:

# filter the data source on time range
data_source <- data_source[.indexhour(min_hour) >= min_hour &
.indexhour(data_source) < max_hour]

# now remove any data for which there is now enough daily samples
# aggregate samples per day
day_samples <- apply.daily(as.xts(data_source[,1]),length)

# get rid of any which do not have enough samples
day_samples <- day_samples[day_samples >= min_samples_per_day]

# get day index of the remaining days
days <- .indexday(as.xts(day_samples))

# filter data by remaining days
data_source <- data_source[.indexday(as.xts(data_source[,1])) %in% days]


Any comments on whether or not this is an optimal solution or acan be
improved in any way would be appreciated.


--
View this message in context:
http://r.789695.n4.nabble.com/Filtering-dates-times-from-zoo-xts-series-tp38
42937p3843065.html
Sent from the Rmetrics mailing list archive at Nabble.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.



More information about the R-SIG-Finance mailing list