An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20111223/30d102df/attachment.pl>
using [ on xts object
5 messages · financial engineer, Joshua Ulrich
Dear Mr. or Mrs. Engineer, On Fri, Dec 23, 2011 at 1:50 PM, financial engineer
<fin_engr at hotmail.com> wrote:
I have the following sample tick data set (Z11): 24990 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24991 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24992 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24993 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24994 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24995 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24996 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24997 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24998 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24999 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B where the second field is the date, third- time, fourth - price, and fifth - bid, ask, or trade I have converted the above into a xts object using the following command z<-xts(Z11[,-1],order.by=as.Date(Z11[,1])) which has resulted in data in the following form 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" I want to split my data based on the hour of the day, ?so I was trying to use the following z['2011-10-31 04/'] to get the data starting from the 04 hour through the end of the day, but it returns the following: z['2011-10-31 04/'] ? ? trade_time trade_price trade_type can anyone pls. suggest how I can split the data into hourly intervals from this xts object.....thanks!
You can't. You created an xts object with a Date class index. The Date class doesn't contain any information about time of day. Use a date/time class (read ?DateTimeClasses). Subsetting xts objects by time of day has been discussed several times on this list. Please search the list archives (e.g. via rseek.org). Regards, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20111223/d83d38fc/attachment.pl>
On Fri, Dec 23, 2011 at 3:17 PM, financial engineer
<fin_engr at hotmail.com> wrote:
Dear Joshua, thanks for your response. I have done the search and have rewritten the code as follows: dt<-cbind(Z11[,1],Z11[,2]) which returned the following: [49994,] "2011-10-31" "0833" ?[49995,] "2011-10-31" "0833" ?[49996,] "2011-10-31" "0833" ?[49997,] "2011-10-31" "0833" ?[49998,] "2011-10-31" "0833" ?[49999,] "2011-10-31" "0833" and then I tried the following: as.POSIXct(as.Date(strptime(as.character(index(dt)),'%Y%m%d %H:%M'))) however, the above returns only NA. It seems like I am making a silly error somewhere, so any help in fixing it would be appreciated.
Errors, plural. 1) You cbind the "date" and "time" columns into a _matrix_ dt. Then you try to extract the index(dt) of the matrix. Matrix class objects don't have an index attribute. 2) You pass a matrix to strptime. ?strptime says "strptime converts character _vectors_ to class POSIXlt" (emphasis added). 3) Even if you didn't make the first two errors, you use as.Date() to effectively remove the time component you set out to add. My intent isn't to be rude. These 'issues' are the result of not understanding some very basic concepts. Doing the work for you and giving you the answer won't help you in the long-term. So, take a step back and examine the results of the individual commands to find where the output isn't what you expect. Then read the documentation to find out why.
thanks, Bobby
Regards, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com
From: josh.m.ulrich at gmail.com Date: Fri, 23 Dec 2011 14:00:18 -0600 Subject: Re: [R-SIG-Finance] using [ on xts object To: fin_engr at hotmail.com CC: r-sig-finance at r-project.org
Dear Mr. or Mrs. Engineer, On Fri, Dec 23, 2011 at 1:50 PM, financial engineer <fin_engr at hotmail.com> wrote:
I have the following sample tick data set (Z11): 24990 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24991 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24992 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24993 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24994 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24995 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24996 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24997 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24998 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B 24999 ?2011-10-31 ? ? ? 0421 ? ? ? ?8900 ? ? ? ? ?B
where the second field is the date, third- time, fourth - price, and fifth - bid, ask, or trade I have converted the above into a xts object using the following command z<-xts(Z11[,-1],order.by=as.Date(Z11[,1])) which has resulted in data in the following form 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" 2011-10-31 "0421" ? ? "8900" ? ? ?"B" I want to split my data based on the hour of the day, ?so I was trying to use the following
z['2011-10-31 04/'] to get the data starting from the 04 hour through the end of the day, but it returns the following: z['2011-10-31 04/'] ? ? trade_time trade_price trade_type
can anyone pls. suggest how I can split the data into hourly intervals from this xts object.....thanks!
You can't. You created an xts object with a Date class index. The Date class doesn't contain any information about time of day. Use a date/time class (read ?DateTimeClasses). Subsetting xts objects by time of day has been discussed several times on this list. Please search the list archives (e.g. via rseek.org). Regards, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20111223/c204edee/attachment.pl>