[R] plotOHLC(alpha3): Error in plotOHLC(alpha3) : x is not a open/high/low/close time series

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Jan 11 21:16:00 CET 2012


On Wed, Jan 11, 2012 at 11:10 AM, Ted Byers <r.ted.byers at 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



More information about the R-help mailing list