[R-SIG-Finance] Create a Monday-Friday time series?
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jan 6 22:33:17 CET 2011
On Thu, Jan 6, 2011 at 12:55 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
>> Cheers,
>> Murali
>>
>> -----Original Message-----
>> From: r-sig-finance-bounces at r-project.org [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Mark Knecht
>> Sent: 06 January 2011 17:19
>> To: R-Finance
>> Subject: [R-SIG-Finance] Create a Monday-Friday time series?
>>
>> Hi,
>> I think I'm going to have a couple of questions but I figured I'd
>> start with (I hope) a very simple one. I've not worked with time
>> series objects before so I'm trying to learn them. I've been looking
>> at things like ?xts, ?zoo as well as Phil Proctor's book but so far no
>> luck.
>>
>> Starting from this little code stub I'd like to create a Monday
>> through Friday time series into which I can eventually place trading
>> system results.
>>
>> Here's the stub:
>>
>> TStoDate = function (TSDate) {
>> X = strptime(TSDate + 19e6L, "%Y%m%d")
>> return(as.Date(X))
>> }
>>
>> # TradeStation date format
>> FirstDate = 1100401
>> LastDate = 1100601
>>
>> #Dates
>> StartDate = TStoDate(FirstDate)
>> EndDate = TStoDate(LastDate)
>>
>> StartDate
>> EndDate
>>
>> How can I do this, and (if possible and easy) is there a way to
>> exclude U.S. holidays?
>>
>> I did discover
>>
>> R1 <- as.zoo(StartDate:EndDate )
>>
>> does create an object, but the values are numbers which I don't
>> understand but suspect are some internal R code for a date, and it
>> appears to have enough entries to include weekends.
>>
>> Anyway, hopefully this is clear enough to describe what I'm trying
>> to do and where I'm stuck.
>>
> On Thu, Jan 6, 2011 at 12:29 PM, <Murali.Menon at avivainvestors.com> wrote:
>> Hi,
>>
>> For US holidays, the timeDate package in Rmetrics has a function holidayNYSE() to which you pass a numeric range for years, e.g. holidayNYSE(1980:1990).
>>
>
> To add to this try:
>
> library(timeDate) # holidayNYSE
> library(chron) # .Holidays / is.holiday / is.weekend
>
> # this will be used by is.holiday
> .Holidays <- chron(as.Date(holidayNYSE(year = 2010)))
That should as.chron, rather than chron, i.e.
.Holidays <- as.chron(as.Date(holidayNYSE(year = 2010)))
>
> StartDate <- as.Date("2010-01-01")
> EndDate <- as.Date("2010-04-01")
>
> dd <- seq(StartDate, EndDate, by = "day")
>
> dd[!is.weekend(dd) & !is.holiday(dd)]
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-SIG-Finance
mailing list