Question

I am trying to plot some Chinese stocks using quantmod. But the problem is that the chart always showed me the none trading day, such as the weekend and the holiday. I am wonder how to remove those days to make the chart continuous.

library("quantmod")

s <- getSymbols("002389.SZ",auto.assign=FALSE)   
head(s)

chartSeries(s, theme = "white", subset = "last 6 months",TA = "addSMA(n=5,col=\"gray\");addSMA(n=10,col=\"yellow\");
                addSMA(n=20,col=\"pink\");addSMA(n=30,col=\"green\");addSMA(n=60,col=\"blue\");addVo()")
Was it helpful?

Solution

I don't think that's a holiday (2013-11-13 through 2014-01-27); it's either bad data, or the stock didn't trade for several days at a time (look at the volume). If you want to only plot days when the volume is above zero, you can remove those rows before plotting.

x <- s[Vo(s)>0]
chartSeries(x, theme = "white", subset = "last 6 months",TA = "addSMA(n=5,col=\"gray\");addSMA(n=10,col=\"yellow\");addSMA(n=20,col=\"pink\");addSMA(n=30,col=\"green\");addSMA(n=60,col=\"blue\");addVo()")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top