Copper-Price-Forecasting-using-SARIMA-Method-in-Python

This time I would like to run SARIMA method in order to forecast the price of copper. The data is downloaded as monthly historical data from yahoo finance in range of 5 years period from Jul 08, 2016 - Jul 08, 2021.

  1. We need to import and install related libraries

textimage

  1. Entry SARIMAX line of code in order to run SARIMA model

from statsmodels.tsa.statespace.sarimax import SARIMAX

  1. import the data Cppr.xlsx and convert into panda dataframes

textimage

  1. Put Date as index of the data

textimage

  1. Replace missing value with mean

textimage

  1. Run seasonal decompose code, visualize it.

textimage

  1. After we observed all the graphs, we decided to run it using the order that based on ARIMA model, and the seasonal order is run based on seasonal model.

model = SARIMAX(df['Adj Close'], order=(2,1,2), seasonal_order=(1,1,1,12))

model_fit = model.fit()

  1. Plot the residuals. As we can see the residuals are centered around zero. There is no trend and seasonality in the model and look a like a white noise and we can say that there is information that could be extracted from the dataset.

textimage

  1. Obtain the forecasted values. As we can see the last data available is on July 2021, and we get the forecast start from August

textimage

textimage

  1. Obtain the predicted values from the beginning date of the data

textimage

  1. visualize the graph

textimage