I am using library(forecast)
to create quarterly forecasts based on quarterly data. My forecasts are saved in a forecast
object. I am trying to find an elegant and simple way of transforming those to the corresponding annual values, taking the mean of all 4 quarters fine.
Is there an option in the forecast
package that allows to do this? Or alternatively, if there a way of transforming the quarterly values?
I tried to convert the forecast
object into a timeseries
object and merge it with the original time series that I used to create the forecasts but that did not work.
Below is an example:
library('quantmod')
library('xts')
library('forecast')
library(zoo)
library(tis)
library(astsa)
library(xts)
GDP_SAAR<-getSymbols('A191RL1Q225SBEA',src='FRED', auto.assign=FALSE)
GDP_SAAR <- ts(GDP_SAAR , start=c(1947, 2), end=c(2017, 3), frequency=4)
fit <- auto.arima(GDP_SAAR)
x<-forecast(fit,h=7)
I do not know if it is still of interest to you, but here is a solution involving 12 steps (quarters) ahead in order to include at least 3 years of aggregated forecasts:
GDP_SAAR<-getSymbols('A191RL1Q225SBEA',src='FRED', auto.assign=FALSE)
fit <- auto.arima(GDP_SAAR)
x<-forecast(fit,h=12)
DateTime=as.Date(seq(from=tail(index(GDP_SAAR),1),by="quarter",length.out = length(x$mean)+1))
myresult=tibble(Forecasts=x$mean,DateTime=DateTime[-1])%>%mutate(DateTime=year(DateTime))%>%
group_by(DateTime)%>%summarize(Forecasts=sum(Forecasts,na.rm=T))
> myresult
# A tibble: 3 x 2
DateTime Forecasts
<int> <dbl>
1 2018 10.5
2 2019 10.6
3 2020 10.6
Hope this helps