[R-SIG-Finance] stripping holidays from timeSeries() class time series

Joshua Ulrich josh.m.ulrich at gmail.com
Wed May 9 22:51:08 CEST 2012


You don't need the call to which() and its results may confuse you if
there are no matches, in which case your code below will return
whatever tsm[integer(0)] returns.

Try this instead:
tsm[!(as.Date(time(tsm)) %in% as.Date(index.holidays)),]

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

R/Finance 2012: Applied Finance with R
www.RinFinance.com


On Wed, May 9, 2012 at 3:15 PM, David-Michael Lincke <dlincke at lincke.com> wrote:
> Turns out that the following accomplishes the same:
>
> tsm[-which(as.Date(time(tsm)) %in% as.Date(index.holidays)),]
>
> However, I still wonder if there is not a more elegant way to achieve this while remaining within the timeDate/timeSeries classes.
>
> ________________________________________
> From: r-sig-finance-bounces at r-project.org [r-sig-finance-bounces at r-project.org] on behalf of David-Michael Lincke [dlincke at lincke.com]
> Sent: Wednesday, May 09, 2012 21:33
> To: r-sig-finance at r-project.org
> Subject: [R-SIG-Finance] stripping holidays from timeSeries() class time        series
>
> I have come up with the following expression to strip a time series tsm of class timeSeries from holidays contained in timeDate class object index.holidays. index.holidays covers a wider date range than time series tsm.
>
> tsm[-na.omit(match(as.character(index.holidays),as.character(time(tsm)))),]
>
> While this expression works as intended, I suspect that it is rather inefficient due to the data type conversions forced by match(). Is there a more elegant way to accomplish this?
>
> Best regards,
> David
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> 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.
>
> _______________________________________________
> 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