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.
- We need to import and install related libraries
- Entry SARIMAX line of code in order to run SARIMA model
from statsmodels.tsa.statespace.sarimax import SARIMAX
- import the data Cppr.xlsx and convert into panda dataframes
- Put Date as index of the data
- Replace missing value with mean
- Run seasonal decompose code, visualize it.
- 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()
- 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.
- Obtain the forecasted values. As we can see the last data available is on July 2021, and we get the forecast start from August
- Obtain the predicted values from the beginning date of the data
- visualize the graph