[R-SIG-Finance] Problems with xts and plotting charts in quantmod

Tom Clifford tjclifford at yahoo.com
Fri Feb 6 00:25:28 CET 2015


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:
> I appreciate your help and contribution. I followed the above codes and
> encountered an error:
> *Error in na.omit.xts(x) : unsupported type*
>
> I found other's post on SO with my similar question but unfortunately no
> solution yet:
> http://stackoverflow.com/questions/28255994/error-in-na-omit-xtsx-unsupported-type-with-chartseries
>
> Just post the output here to see if you can see the problem:
>
>> >chartSeries(data.xts,subset="2015-01",type="candlesticks")
> *Error in na.omit.xts(x) : unsupported type*
>> >head(data.xts)
>                      Date Time        Open      High      Low      Close
>
> 2009-03-15 17:00:00 "20090315 170000" " 929.60" " 929.60" " 929.60" "
> 929.60"

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.


   
	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list