Skip to content
Prev 13136 / 15274 Next

Problems with xts and plotting charts in quantmod

I've been looking at this today, and I was able to get this working by using a csv file that 
I put the data into, and used the following data and code:
used a csv file:
DateTime,Open,High,Low,Close
20150101 180100,1184.13,1184.44,1184.04,1184.13
20150101 180200,1184.12,1184.41,1184.12,1184.41
20150101 180300,1184.53,1184.54,1184.32,1184.54
20150101 180400,1184.60,1184.60,1184.43,1184.51

code:

library(quantmod)
ColClasses = c("character", "numeric", "numeric", "numeric", "numeric")

ohlcdata <- read.zoo("./data-file.csv", 
???????????????????? index.column = 1, 
???????????????????? sep = ",",
???????????????????? tz='',
???????????????????? format="%Y%m%d %H%M%S", 
???????????????????? colClasses = ColClasses,
???????????????????? header=TRUE)
as.xts(ohlcdata)

chartSeries(ohlcdata,type="candlesticks")

It does produce the chart, and I hope it is what you're looking for.Let me know if you have trouble.
?Tom Clifford MBA '13
Lansing, Michigan 48912
tjclifford at yahoo.com
On Thursday, February 5, 2015 1:25 PM, Brian G. Peterson <brian at braverock.com> wrote:
at least part of your problem now is that you're storing the data as 
character, rather than numeric.

in your as.xts call, you'll want to remove the first column in the 'x' 
argument,

e.g.

y <- as.xts(x[,-1], order.by=as.POSIXct(x[,1],...))
# the above is not reproducible, it is missing the format argument at least

I also see that you have spaces in your character data, so you may need 
an as.numeric in there too.

Another way to do it would be to make sure that read.csv sees the 
columns as numbers rather than character, which proably has to do with 
your choice of separator.

Regards,

Brian
On 02/05/2015 10:44 AM, Liu wrote: