Automatic Identification of Model Using auto.arima() Function in R

auto.arima() Function

R also has a package called forecast, which contains many forecasting functions for time series and linear models. It also contains a very useful function called auto.arima, which returns the best ARIMA model according to either AIC, AICc or BIC value. The function conducts a search over possible models within the order constraints provided.

Let's try the auto.arima function on our time series.

> fb\_fit\_auto <- auto.arima(fb\_ts)
> fb\_fit\_auto
Series: fb\_ts
ARIMA(1,1,4) with drift
Coefficients:
          ar1     ma1      ma2      ma3      ma4   drift
      -0.8405  0.8626  -0.0123  -0.1632  -0.1768  0.0800
s.e.   0.1080  0.1111   0.0488   0.0509   0.0381  0.0478
sigma^2 estimated as 2.581:  log likelihood=-1426.29
AIC=2866.58   AICc=2866.73   BIC=2898.97
>

The auto.arima function suggests the best fit model as ARIMA(1,1,4) with drift.

The following code creates the forecast for the FB stock prices using the suggested model:

fb\_fit <- arima(fb\_ts, order = c(1, 1, 4))
fb\_forecast <- predict(fb\_fit , n.ahead = 20)
fb\_forecast\_values <- fb\_forecast$pred
plot.ts(fb\_ts, xlim = c(0, 900), ylim = c(50,160))
points(fb\_forecast\_values , type = "l", col = 2)

Related Downloads

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book includes PDFs, explanations, instructions, data files, and R code for all examples.

Get the Bundle for $39 (Regular $57)
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book comes with PDFs, detailed explanations, step-by-step instructions, data files, and complete downloadable R code for all examples.