I'm new to ts, and xts object.
When dealing with time series data, I encountered the problem
require(quantmod)
require(forecast)
ticker <- "^GSPC"
getSymbols(ticker, src="yahoo", to = "2013-12-31")
prices <- GSPC[,6] # First get data using package quantmod
# then forecasting using package forecast
prices.ts <- as.ts(prices)
prices.ets <- ets(prices.ts)
prices.fore <- forecast(prices.ets, h=10)
# then plot
plot(prices.fore, xaxt = "n")
My problems are :
1 . When I tried to save the GSPC with date in a csv file. I searched and tried this
write.zoo((GSPC, file = "GSPC.csv", sep = ",", qmethod = "double"))
The error message: Error: unexpected ',' in "write.zoo((GSPC,"
, I checked the syntax, it seems to be correct, and I tried other combinations. All failed with the similar error message.
also I tried index(GSPC)
to get the date.
and then cbind(index(GSPC), GSPC[, 6])
. It also failed..
Error message: Error in merge.xts(..., all = all, fill = fill, suffixes = suffixes) :
dims [product 1762] do not match the length of object [3524]
but when I checked the length
> length(GSPC[,6])
[1] 1762
> length(index(GSPC))
[1] 1762
2 . the plot is like this
there's no x-lab and y- lab. I tried the methods of accepted answer posted here, . but failed.
Especially, I don't get the purpose of the following code. It seems to change the appearance of the plot, but it doesn't change the appearance at all. I don't know whether I lose some points.
a = seq(as.Date("2011-11-01"), by="weeks", length=11)
axis(1, at = decimal_date(a), labels = format(a, "%Y %b %d"), cex.axis=0.6)
abline(v = decimal_date(a), col='grey', lwd=0.5)
Also, I want to plot from as.Date("2013-01-01").
Could you please give some suggestions?
Thanks a lot!