Time Series get. best. arima Error: possible convergence problem: optim gave code = 1

I am using the stock market data available from Git Hub. It is from Paul S.P. Cowpertwait and Andrew V. Metcalfe's Introductory Time Series with R.

I used the reprex package; however, the code is long because our professor wants us to use his code, but it is not working. I keep getting these endless warnings every time I run his code. Is there any way to get rid of the warnings the code produces? Any help is always greatly appreciated.

Please help!

https://github.com/prabeshdhakal/Introductory-Time-Series-with-R-Datasets/blob/master/stockmarket.dat

class(stockmarket)
#> [1] "data.frame"
stockmarket.ts=ts(stockmarket)
class(stockmarket.ts)
#> [1] "mts"    "ts"     "matrix"

par(col.main="blue", col.lab="blue4")

Amsterdam.ts= ts(stockmarket$Amsterdam, start=1986,end=1997, frequency = 12)

get.best.arima <- function(x.ts, maxord = c(1,1,1,1,1,1)){
  best.aic <- 10^9
  n <- length(x.ts)
  for(p in 0:maxord[1])
    for(d in 0:maxord[2])
      for(q in 0:maxord[3])
        for(P in 0:maxord[4])
          for(D in 0:maxord[5])
            for(Q in 0:maxord[6]){
              fit <- arima(x.ts, order = c(p,d,q),
                           seas = list(order=c(P,D,Q),
                                       frequency(x.ts)), method="CSS")
              fit.aic <- -2*fit$loglik +
                (log(n) + 1)* length(fit$coef)
              if(fit.aic < best.aic){
                best.aic <- fit.aic
                best.fit <- fit
                best.model <- c(p,d,q,P,D,Q)
              }
            }
  list(best.aic, best.fit, best.model)
}

Amsterdam.best <- get.best.arima(Amsterdam.ts, maxord = rep(2,6))
#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1

#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1

#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1

#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1

#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1

#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1

#> Warning in arima(x.ts, order = c(p, d, q), seas = list(order = c(P, D, Q), :
#> possible convergence problem: optim gave code = 1
Amsterdam.best
#> [[1]]
#> [1] 635.5502
#> 
#> [[2]]
#> 
#> Call:
#> arima(x = x.ts, order = c(p, d, q), seasonal = list(order = c(P, D, Q), frequency(x.ts)), 
#>     method = "CSS")
#> 
#> Coefficients:
#>           ma1     sar1     sar2     sma1
#>       -1.0607  -0.5964  -0.3313  -0.6320
#> s.e.   0.0069   0.0171   0.0133   0.0906
#> 
#> sigma^2 estimated as 17.84:  part log likelihood = -305.99
#> 
#> [[3]]
#> [1] 0 2 1 2 2 1

Created on 2021-11-26 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.