Re: [R] plotOHLC(alpha3): Error in plotOHLC(alpha3) : x is not a open/high/low/close time series
Hi Ted, On Tue, Jan 10, 2012 at 1:59 PM, Ted Byers r.ted.by...@gmail.com wrote: R version 2.12.0, 64 bit on Windows. Here is a short script that illustrates the problem: library(tseries) library(xts) setwd('C:\\cygwin\\home\\Ted\\New.Task\\NKs-01-08-12\\NKs\\tests') x = read.table(quotes_h.2.dat, header = FALSE, sep=\t, skip=0) str(x) y - data.frame(as.POSIXlt(paste(x$V2,substr(x$V4,4,8),sep= ),format='%Y-%m-%d %H:%M'),x$V5) colnames(y) - c(tickdate,price) str(y) plot(y) z - as.irts(y) str(z) plot(z) str(alpha3) List of 2 $ time : POSIXt[1:98865], format: 2010-06-30 15:47:00 2010-06-30 15:53:00 2010-06-30 17:36:00 ... $ value: num [1:98865, 1:4] 9215 9220 9205 9195 9195 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr [1:4] z.Open z.High z.Low z.Close - attr(*, class)= chr ts - attr(*, tsp)= num [1:3] 1 2 1 This is a big clue. Your alpha3 object is a list with two elements 1) the datetime, and 2) the OHLC values as a ts object. There's no as.xts() method for this type of object. alpha3 - as.xts(to.minutes3(z,OHLC = TRUE)) Look at str(z). Why did you convert z to an irts object instead of directly to an xts object? to.minutes() expects an xts object. Try something like this instead: z - xts(y[,2], y[,1]) alpha3 - to.minutes3(z, OHLC=TRUE) plotOHLC(alpha3) Error in plotOHLC(alpha3) : x is not a open/high/low/close time series The file quotes_h.2.dat contains real time tick data for futures contracts, so the above manipulation is my attempt to just get a time series with one column being a date/time and the other being tick price. I believe I have to use read.table to make a data frame, and then the manipulations to combine the date and time fields from that feed, along with the price. My first attempt at using to.minutes3 (and I am interested in the other 'to.period' functions too), is to get a regular time series to which I can apply rollapply, along with a function in which I use various autoregression methods, along with forecasting for as long as the 95% confidence intervals is reasonably close - I want to know how far into the future the forecast contains useful information. And then, I want to create a plot in which I do the autoregression, and then plot the actual and forecast prices (along with the confidence interval), as a function of time, embed that in a function, which rollappply works with, so I can have a plot comprised of all those individual plots (plotting only the comparison of actual and forecast values). It seems everything works adequately until I try the plotOHLC function itself, which gives me the error in the subject line. I would ask for two things: 1) what the fix is to get rid of that error plotOHLC gives me 2) some tips on the 'walk-forward' method I am looking at using. Thanks Ted [[alternative HTML version deleted]] __ R-help@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. -- Joshua Ulrich | FOSS Trading: www.fosstrading.com __ R-help@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.
Re: [R] plotOHLC(alpha3): Error in plotOHLC(alpha3) : x is not a open/high/low/close time series
Hi Joshua, Thanks. I had used irts because I thought I had to. The tick data I have has some minutes in which there is no data, and others when there are hundreds, or even thousands. If xts supports irregular data, the that is one less step for me to worry about. Alas, your suggestion didn't help: z - xts(y[,2], y[,1]) alpha3 - to.minutes3(z, OHLC=TRUE) plotOHLC(alpha3) Error in plotOHLC(alpha3) : x is not a open/high/low/close time series str(alpha3) An ‘xts’ object from 2010-06-30 15:47:00 to 2011-10-31 15:14:00 containing: Data: num [1:98865, 1:4] 9215 9220 9205 9195 9195 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:4] z.Open z.High z.Low z.Close Indexed by objects of class: [POSIXct,POSIXt] TZ: xts Attributes: NULL Is there anything else I might try? Thanks again, Ted -- View this message in context: http://r.789695.n4.nabble.com/plotOHLC-alpha3-Error-in-plotOHLC-alpha3-x-is-not-a-open-high-low-close-time-series-tp4283217p4286124.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] plotOHLC(alpha3): Error in plotOHLC(alpha3) : x is not a open/high/low/close time series
On Wed, Jan 11, 2012 at 11:10 AM, Ted Byers r.ted.by...@gmail.com wrote: Hi Joshua, Thanks. I had used irts because I thought I had to. The tick data I have has some minutes in which there is no data, and others when there are hundreds, or even thousands. If xts supports irregular data, the that is one less step for me to worry about. Alas, your suggestion didn't help: z - xts(y[,2], y[,1]) alpha3 - to.minutes3(z, OHLC=TRUE) plotOHLC(alpha3) Error in plotOHLC(alpha3) : x is not a open/high/low/close time series plotOHLC requires a 4-column ts object with columns explicitly named Open, High, Low, Close, in that order. alpha3, as I've defined above, will have 4 columns but may not have those explicit column names. You would have to set them yourself. Then you could run: plotOHLC(as.ts(alpha3)) For example, this works: library(xts) data(sample_matrix) x - as.ts(sample_matrix) plotOHLC(x) str(alpha3) An ‘xts’ object from 2010-06-30 15:47:00 to 2011-10-31 15:14:00 containing: Data: num [1:98865, 1:4] 9215 9220 9205 9195 9195 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:4] z.Open z.High z.Low z.Close Indexed by objects of class: [POSIXct,POSIXt] TZ: xts Attributes: NULL Is there anything else I might try? You could try quantmod::chartSeries(to.minutes3(z, OHLC=TRUE)). I'm not familiar with the charting capabilities in the tseries package, but those in quantmod are quite extensive. See also www.quantmod.com. Thanks again, Ted Best, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com __ R-help@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.
Re: [R] plotOHLC(alpha3): Error in plotOHLC(alpha3) : x is not a open/high/low/close time series
Thanks Joshua, That did it. Cheers, Ted -- View this message in context: http://r.789695.n4.nabble.com/plotOHLC-alpha3-Error-in-plotOHLC-alpha3-x-is-not-a-open-high-low-close-time-series-tp4283217p4286963.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] plotOHLC(alpha3): Error in plotOHLC(alpha3) : x is not a open/high/low/close time series
R version 2.12.0, 64 bit on Windows. Here is a short script that illustrates the problem: library(tseries) library(xts) setwd('C:\\cygwin\\home\\Ted\\New.Task\\NKs-01-08-12\\NKs\\tests') x = read.table(quotes_h.2.dat, header = FALSE, sep=\t, skip=0) str(x) y - data.frame(as.POSIXlt(paste(x$V2,substr(x$V4,4,8),sep= ),format='%Y-%m-%d %H:%M'),x$V5) colnames(y) - c(tickdate,price) str(y) plot(y) z - as.irts(y) str(z) plot(z) str(alpha3) List of 2 $ time : POSIXt[1:98865], format: 2010-06-30 15:47:00 2010-06-30 15:53:00 2010-06-30 17:36:00 ... $ value: num [1:98865, 1:4] 9215 9220 9205 9195 9195 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr [1:4] z.Open z.High z.Low z.Close - attr(*, class)= chr ts - attr(*, tsp)= num [1:3] 1 2 1 alpha3 - as.xts(to.minutes3(z,OHLC = TRUE)) plotOHLC(alpha3) Error in plotOHLC(alpha3) : x is not a open/high/low/close time series The file quotes_h.2.dat contains real time tick data for futures contracts, so the above manipulation is my attempt to just get a time series with one column being a date/time and the other being tick price. I believe I have to use read.table to make a data frame, and then the manipulations to combine the date and time fields from that feed, along with the price. My first attempt at using to.minutes3 (and I am interested in the other 'to.period' functions too), is to get a regular time series to which I can apply rollapply, along with a function in which I use various autoregression methods, along with forecasting for as long as the 95% confidence intervals is reasonably close - I want to know how far into the future the forecast contains useful information. And then, I want to create a plot in which I do the autoregression, and then plot the actual and forecast prices (along with the confidence interval), as a function of time, embed that in a function, which rollappply works with, so I can have a plot comprised of all those individual plots (plotting only the comparison of actual and forecast values). It seems everything works adequately until I try the plotOHLC function itself, which gives me the error in the subject line. I would ask for two things: 1) what the fix is to get rid of that error plotOHLC gives me 2) some tips on the 'walk-forward' method I am looking at using. Thanks Ted [[alternative HTML version deleted]] __ R-help@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.