0

Hi and thanks for reading me.

I am working with an ARIMA model and I would like to convert the model to a DataFrame and then export it together with the database, but the date format is not correct. Dates should be in the format: "yyyy-mm-dd". For example, im getting "2007.000" instead "2007-01-03". Is there a way to fix it?

The codes im using are the following:

library(ggplot2)
library(quantmod)
library(forecast)

getSymbols("GOOG")
data <-  as.data.frame(GOOG) |> 
  tibble::rownames_to_column("Fecha") 
ts_data <- ts(data$GOOG.Close, start = 2007, frequency = 365)
d.arima <- forecast::auto.arima(ts_data)
d.forecast <- forecast::forecast(d.arima, level = c(95), h = 50)
data <- fortify(d.forecast, ts.connect = TRUE)

I would expect the table (and date format) to look like this:

head(data)

 "|    Index  |      Data|    Fitted| Point Forecast|     Lo 95|    Hi 95|"
 "|----------:|---------:|---------:|--------------:|---------:|--------:|"
 "| 2007-01-03|  232.9220|  232.8178|             NA|        NA|       NA|"
 "| 2007-01-04|  240.7277|  241.0227|             NA|        NA|       NA|"
 "| 2007-01-05|  242.6853|  247.0522|             NA|        NA|       NA|"
 "| 2007-01-06|  240.8871|  247.0309|             NA|        NA|       NA|"

But instead of this I get the following:

head(data)

 "|    Index|      Data|    Fitted| Point Forecast|     Lo 95|    Hi 95|"
 "|--------:|---------:|---------:|--------------:|---------:|--------:|"
 "| 2007.000|  232.9220|  232.8178|             NA|        NA|       NA|"
 "| 2007.003|  240.7277|  241.0227|             NA|        NA|       NA|"
 "| 2007.005|  242.6853|  247.0522|             NA|        NA|       NA|"
 "| 2007.008|  240.8871|  247.0309|             NA|        NA|       NA|"

Thanks for the help

  • Hi Jorge, it always help if you put a reproducible example here ... or at least a dput() or head(xx, 10) of the object that causes trouble. There are many timestamp coercion/conversion functions in R. Could you let us know what `d.forcast` or at least the date column looks like? This will help getting it into the right format. – Ray Oct 03 '21 at 08:59
  • @Ray Thanks a lot for the help. I update the question with an example of what the final database should look like and how it looks when I run the code – Jorge Hernández Oct 03 '21 at 09:27
  • Ok. we are getting there. I am not a timeseries expert so bear with me. What happens with the "time format" when you create ts_data(). I suppose the ts() call with frequency 365 should keep a "daily" timestamp. Please also check out https://stackoverflow.com/questions/33128865/starting-a-daily-time-series-in-r where the discussion is about starting a daily timeseries at certain days. I guess this is where it goes wrong and the index is scrambled. – Ray Oct 03 '21 at 09:44

0 Answers0