[R] Query about creating time sequences

R. Michael Weylandt michael.weylandt at gmail.com
Mon May 28 02:30:07 CEST 2012


Depending on your exchange of interest, you might also find some of
the functions of the timeDate package helpful, e.g., holidayNYSE() --
it will miss the day the market was closed for extraordinary
circumstances, but it seems to do a very good job. [Disclaimer: I
haven't used it myself extensively]

Michael

On Sun, May 27, 2012 at 8:26 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Sun, May 27, 2012 at 8:01 PM, Shivam <shivamsingh at gmail.com> wrote:
>> Its not the number of days per se, it is the random gaps between the dates
>> (corresponding to the dates on which the security market was closed) which
>> will be difficult to accommodate in the solution proposed by you. So I would
>> have to remove the sequence corresponding to those days from the entire
>> sequence. This was the part which I deemed as difficult to achieve.
>> I had mentioned this issue in my previous mails but you might have missed
>> it.
>>
>
> If dd is a vector of the dates you want then just change the last line
> to choose only those using as.Date(tseq, tz = "") %in% dd as below:
>
> dd <- as.Date(c("2011-01-03", "2011-01-04")) ##
>
> from <- as.POSIXct(paste(dd[1], "09:15:00")) ##
> to <- as.POSIXct(paste(tail(dd, 1), "15:30:00")) ##
>
> tseq <- seq(from, to, "1 min")
>
> tt <- format(tseq, "%H:%M:%S")
> tresult <- tseq[tt >= "09:30:00" & tt <= "15:30:00" & as.Date(tseq, tz
> = "") %in% dd] ##
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list