 # 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.

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

class(stockmarket)
#>  "data.frame"
stockmarket.ts=ts(stockmarket)
class(stockmarket.ts)
#>  "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)
for(d in 0:maxord)
for(q in 0:maxord)
for(P in 0:maxord)
for(D in 0:maxord)
for(Q in 0:maxord){
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
#> []
#>  635.5502
#>
#> []
#>
#> 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
#>
#> []
#>  0 2 1 2 2 1

``````

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