<R>
#for daily time series forecasting and plot the forecasting result, ref : http://robjhyndman.com/hyndsight/longseasonality/
n <- 2000
m <- 200
y <- ts(rnorm(n) + (1:n)%%100/30, f=m)
fourier <- function(t,terms,period)
{
n <- length(t)
X <- matrix(,nrow=n,ncol=2*terms)
for(i in 1:terms)
{
X[,2*i-1] <- sin(2*pi*i*t/period)
X[,2*i] <- cos(2*pi*i*t/period)
}
colnames(X) <- paste(c("S","C"),rep(1:terms,rep(2,terms)),sep="")
return(X)
}
library(forecast)
fit <- Arima(y, order=c(2,0,1), xreg=fourier(1:n,4,m))
print(fit$aicc)
pred = forecast(final_fit, h=2*m, xreg=fourier(n+1:(2*m),final_k,m))
plot(pred)
# finish plotting the forecasting result.
print(pred$mean)# this is the forecasting values in the forecasting interval.
# The code below
Example code with given Fourier series order K<R>#for daily time series forecasting and plot the forecasting result, ref : http://robjhyndman.com/hyndsight/longseasonality/n <- 2000m <- 200y <- ts(rn