Forecasting crude oil price using LSTM neural networks

: As a key input factor in industrial production, the price volatility of crude oil often brings about economic volatility, so forecasting crude oil price has always been a pivotal issue in economics. In our study, we constructed an LSTM (short for Long Short-Term Memory neural network) model to conduct this forecasting based on data from February 1986 to May 2021. An ANN (short for Artificial Neural Network) model and a typical ARIMA (short for Autoregressive Integrated Moving Average) model are taken as the comparable models. The results show that, first, the LSTM model has strong generalization ability, with stable applicability in forecasting crude oil prices with different timescales. Second, as compared to other models, the LSTM model generally has higher forecasting accuracy for crude oil prices with different timescales. Third, an LSTM model-derived shorter forecast price timescale corresponds to a lower forecasting accuracy. Therefore, given a longer forecast crude oil price timescale, other factors may need to be included in the model.


Introduction
Crude oil is a key input factor in industrial production (Zhong et al., 2019). According to the economics principle, the price fluctuation of crude oil is determined by the balance of supply and demand, which is too complicated to forecast. However, it is very necessary for us to conduct this forecasting. The reasons are multi-fold, one of which is that the changes in oil price often directly affect the price of its related products, such as the petroleum fuel and other industrial raw materials, and thus will affect the prices of industrial products. Therefore, when central banks and governments assess macroeconomic risks and make macroeconomic forecasts, crude oil price is always considered to be one of the crucial variables. The other reason is that the fluctuation of oil price can be passed to oil-related enterprises along the value chain. For example, when the oil price rises sharply, the cost of transportation will rise rapidly and the operating profit will be reduced. On the contrary, when the oil price continues to decline, the enthusiasm for the production of oil refining and chemical enterprises will decline, and the operating profits will also decline. If enterprises can accurately forecast the fluctuation of oil price, it will sharply reduce the cost risk and maintain the stable growth of enterprise profits.
It has always been a pivotal issue in economics to forecast crude oil prices (Zheng and Du, 2019). On the one hand, this forecasting plays an important role in both the domestic economy and global governance . The fluctuation and shock of oil prices have important impacts on the real economy and virtual economy (Chen et al., 2019, Grace and Kanamura, 2020, Li and Liao, 2020, as well as significant effects on import and export trading (Yu et al., 2015). Furthermore, forecasting crude oil price accurately is important for three main types of participants in economic activities. Specifically, it is helpful for policy-makers to set up an appropriate budget (Murat andTokat, 2009, Zhang et al., 2019), for enterprises to ensure reasonable production decisions and cost management (Zhao et al., 2017) and for investors to allocate their assets efficiently, even arbitrage from the price volatility . Therefore, it merits us to concentrate on forecasting crude oil price more accurately.
A significant number of models have been applied to forecast oil price (Abdollahi, 2020, Chiroma et al., 2015, Gori et al., 2007, Lu et al., 2020. Prediction models can be roughly divided into two categories: classic econometric approaches and machine learning methods. First, classic econometric approaches, such as ARIMA random walk models and GARCH (Generalized Auto-Regressive Conditional Heteroskedasticity) models were applied to forecast crude oil price (Lammerdin et al., 2013). Murat and Tokat (2009) researched whether the crack spread futures can predict oil price movement very well. Besides that, they used a random walk model as a baseline to explore the forecasting performance. The results indicated that the crack spread futures performed better than the random walk model. Wei et al., (2010) applied a mass of GARCH-type models to capture the volatility features of the West Texas Intermediate (WTI) and UK North Sea Brent (Brent) prices. They found that nonlinear GARCH-based classical models performed much better than the linear models in terms of capturing the characteristics of two kinds of prices, such as long-term memory and asymmetric volatility. To examine the forecasting abilities of the Hidden Markov EGARCH (Exponential Generalized Autoregressive Conditional Heteroscedastic) model, Lin, Xiao and Li (2020) compared the forecasting abilities of GARCH-type models and Markov regime-switching ones by using the HM-EGARCH model. The empirical results showed that the HM-EGARCH model outperformed other comparable models in terms of predicting the volatility of crude oil prices. He et al., (2012) applied a wavelet-decomposed ensemble model to carry out oil price analysis. The results indicated that this model outperformed the other model in terms of predicting the time-varying heterogeneity of oil prices. Lu et al., (2020) developed a kind of Bayesian model to forecast crude oil prices and utilized the Bayesian model average to predict the oil price. The findings suggested that the dynamic Bayesian structural time series (DBSTS) model performs well for short-term predictions.
Apart from the classical econometric approaches, many machine learning methods have been used for forecasting crude oil price in recent years (Butler et al., 2021, Fan et al., 2021, Li et al., 2019, Zhao et al., 2017. Among these methods, two methods, i.e., the neural network (Mostafa andEl-Masry, 2016, Ramyar andKianfar, 2017) and Support Vector Machine (SVM) methods (Zhao et al., 2017), are the most common methods. They can simulate the complex characteristics of oil prices, for example, the nonlinearity and volatility of crude oil prices. Gori et al., (2007) utilized an adaptive neuro fuzzy inference system model to forecast oil prices in the medium term. Chiroma, Abdulkareem and Herawan (2015) combined a genetic algorithm with the neural network method to forecast the WTI price; they found that their combined method performed much better than the single model. Zhang et al. (2015) combined the Empirical Mode Decomposition (EMD) and Support Vector Regression (SVR) methods to predict the oil price. Zhao et al., (2017) combined stacked de-noising auto-encoders with bootstrap aggregation (bagging) to forecast crude oil prices, ultimately demonstrating superior forecasting ability.
Our study contributes to existing literature in several aspects. First, we have constructed an LSTM model to forecast crude oil prices. Many scholars applied neutral networks to carry out the predictions, but few have applied an LSTM model to predict the crude oil price. Our results suggest that the LSTM model has strong generalization ability. Second, by comparing the accuracy and stability of an LSTM model with ARIMA and ANN models, we prove that the LSTM model is superior as a tool to predict crude oil prices. Third, we compared the accuracy and stability of the LSTM model on three timescales (i.e., short, medium and long term) (Li et al., 2020b) and found that a longer LSTM model-derived forecast price timescale corresponds to a lower forecasting accuracy.
The rest of our paper is structured as follows. In Section 2, we first introduce the LSTM model and a comparison model, and then simply introduce the data sources and descriptive statistics. In the case of Section 3, it vividly shows the fitting effect through numerous figures. Section 4 presents the forecasting effect analysis for the LSTM model. Finally, Section 5 is the conclusion.

Method and data sources
In this section, we first introduce the method of using an LSTM model and other two comparable models, i.e., the ARIMA model and ANN model. Traditional time-series models have made great progress in the field of research on financial market prediction, especially the ARIMA model. As a nonlinear method in the field of artificial intelligence, ANNs can deal with nonlinear, discontinuous and high-frequency multidimensional data, and they have been widely used in financial forecasting. Therefore, in this section, we present the ARIMA and ANN models as the reference methods.

LSTM model
The LSTM model is a new type of deep machine learning neural network based on recurrent neural network (RNN) models. Hochreiter and Schmidhuber (1997) first came up with and improved this model, and then Graves (2012) extended it, with focus on the process of deep learning and development. One of the key advantages of RNNs is that they can connect the previous information to the current task (Pabuç cu et al., 2020); that is, the previous information can be memorized and applied for the calculation of the current output, and the time-series data can be analyzed and predicted. LSTM mainly solves the problems of RNNs, such as gradient disappearance and gradient explosion (Fischer and Krauss, 2018). LSTM constructs a long-term delay between input, output and gradient burst prevention. It has its own memory and can yield accurate predictions of crude oil prices. Besides that, LSTM models have excellent long-term and short-term memory ability, which will not lead to the loss of more historical state information on crude oil prices. It can fully extract historical information on the crude oil price and consider the characteristics of the current data for price information. LSTM models have great advantages in terms of mining the long-term dependence of crude oil price sequence data. Furthermore, LSTM models can automatically search for nonlinear features and complex patterns of crude oil prices, which shows excellent forecasting performance in crude oil price prediction. As a very powerful prediction tool, LSTM has been widely used in prediction-related fields. Therefore, in order to forecast crude oil price more accurately, we have selected the LSTM model for this study.
The cell structure of LSTM consists of a cell state and three gates, which are the input, forget and output gates. The cell state records the state of neurons through memory storage, which is the core of the LSTM unit structure. However, whether the cell state is remembered depends on the control gate, which allows crude oil price information to be selectively transmitted; it has the advantages of adding information to the cell state or removing the information so as to defend and regulate the cell state. It contains a sigmoid layer and a pointwise multiplying computation.
Here, we use an LSTM model to conduct this forecasting analysis. In the construction of the LSTM model, a batch-normalization (BN) layer and dropout layer were added to optimize the structure of the neural network. There are two problems, which may directly affect the training capability. One is the problem of gradient disappearance, which makes model convergence difficult. The other is that the tests may fail because of overfitting. As for these problems, BN can effectively address the problem of gradient disappearance, and dropout technology can alleviate the problem of overfitting (Ouyang et al., 2021). For this study, the LSTM model consists of three LSTM neural layers and two others closely connected ones. Each LSTM layer consists of 200 nodes. Before each LSTM neural layer, a BN layer was added, followed by a dropout layer; the inactivation probability was set as 0.2. Furthermore, we used a mini-batch method to train the LSTM network and selected the mean squared error (MSE) as the loss function. Compared with other algorithms, the adaptive moment estimation (Adam) algorithm has the advantages of faster convergence speed and a better learning effect. Therefore, the Adam optimizer was selected for optimization training.

Comparison models
To compare the predictive accuracy among different models, we applied the ARIMA model and ANN model as the comparison models.

ARIMA model
During the past three decades, the ARIMA model has been widely used as a popular linear model for time-series forecasting (Li et al., 2020a). Due to its linear characteristics, the ARIMA model does well in dealing with linear sequences. However, ARIMA models are not able to exhibit the nonlinear feature of crude oil prices.
To set up an ARIMA model often takes three steps. First, we need to identify and select an appropriate model. We mainly judged whether the model was appropriate by analyzing the independent and identically distributed time-series properties. Besides that, an appropriate degree of differencing was used to construct the stationary crude oil price time series. Then, we used the Autocorrelation Function (ACF) and Partial Autocorrelation Function (PACF) to select the lag order of the AR and MA (Li et al., 2021). The second step is to estimate the parameters. We used the most common method of applying the Akaike information criterion (AIC) (Shibata, 1976) and BIC criterion (Bayesian modification of AIC criterion) (Aho et al.,2016) to select the lag order, q and p. Diagnostic checking of the residual analysis is the final step. We tested whether the residuals were stationary based on their diagnostic statistics. If the residuals were stationary, we applied the residual time series to conduct residual analysis.
In this paper, the model is denoted by ARIMA (p, D, q), which combines AR(p), MA(q) and the differencing term D. Specifically, the ARIMA model is often showed as follows: where L represents the lag operator, denotes the parameters of the autoregressive model, denotes the parameters of the moving average model and denotes the residual errors.

Artificial neural network model
ANN models are often used to simulate complex information processing. Compared with the ARIMA model, this model adds nonlinearity to the activation function so that it can map the nonlinear relationship between the input and output. The essence of ANN model is also a kind of regression model, which imitates the information processing of the human brain. By constantly introducing various parameters, the solution with the allowable error is finally obtained. The advantages of an ANN model are that this model is data-driven and does not need any prior assumptions about the model types. ANN models can identify complex price structures, which is suitable for price forecasting. Besides that, ANN models can correctly deduce the "unseen" part in crude oil prices, even when there is noisy information (Azadeh et al., 2012). Therefore, as a usual nonlinear method in the field of artificial intelligence, ANN models can deal with nonlinear and discontinuous multidimensional data, and thus have been widely used for price forecasting.
In the ANN model, we usually distinguish the information into three layers, i.e., the input, hidden and output layers. The input one gets signals and information from the outside. The output one achieves the processing results. There is a hidden one that lies between the input layer and output layer and cannot be seen from outside of this system. And, the connections between different neurons can show the connection degree among different layers. The number of neurons in the input layer is determined by the oil price. In our study, the Rectified Linear Unit (ReLU) function was added as the activation function to overcome the problem of gradient vanishing. We mainly used the Adam optimizer and computed the loss function as the MSE to select the appropriate parameters.

Evaluation indicators
Considering that there are several models for crude oil forecasting, we needed to choose the best one according to effective evaluation indicators. To compare the forecasting accuracy and stability, in this study, we mainly chose the MSE, mean absolute error (MAE) and standard deviation of absolute percentage error (SDAPE) to effectively evaluate these three models. Specifically, these indicators can be expressed as follows: where n is the number of samples in the training set, ̂ denotes the predictive value and is the true value.
where ̂denotes the predictive value and is the true value. A lower MSE or MAE value means better forecasting performance. The prediction stability was evaluated by using the SDAPE; the smaller the SDAPE value, the higher the prediction stability. Furthermore, the value of SDAPE is in the interval [0, 1]. SDAPE can be expressed as follows: where ̂ denotes the predictive value, is the true value and N denotes the number of samples.

Data sources and descriptive statistics
The purpose of our study was to forecast the crude oil price. To fully evaluate the applicability of LSTM technology for crude oil price prediction, we selected the daily spot prices of the WTI and the Brent crude oil price as the sample. The main reasons for selecting these two kinds of prices are that they are two main global oil markets that have been applied as the benchmark in previous studies (Nonejad, 2020, Yu et al., 2020. Besides that, the sample spans February 10, 1986 to May 17, 2021. The reason for choosing the period from February 10, 1986 to May 17, 2021 is that the crude oil price data started from February 10, 1986 and were empirically analyzed as of May 17, 2021. The crude oil price data were searched from the USA-based Energy Information Administration website. In our study, we constructed an LSTM model for forecasting analysis. According to the usual data set partition rules for LSTM models, we divided the whole sample into the training set and test set. Taking the volatility of crude oil spot prices into consideration, 75% of the samples were applied as the training set to train the LSTM model. In other words, the range of the training set was from February 10, 1986 to December 31, 2009. Besides that, 25% of the samples were applied as the test set, and the rest was the training set. The range of the test set was from January 1, 2010 to May 17, 2021. The training and test sets for these two kinds of crude oil price data can be seen in Figure 1. The training and test sets for the WTI price are shown on the left, while those for the Brent price are on the right. As can be seen in Figure 1, both kinds of prices have been fluctuating greatly since around 2007. During the 1990s, the prices were largely stable, but this stable period ended in early 1999 with the rise of world oil consumption (Ajmi et al., 2021). Besides that, in the 2000s, commodity prices generally rose, and crude oil prices rose even more. Particularly, crude oil prices exhibited a longer explosive behavior from March 2008 to July 2008 (James, 2009). Then, crude oil prices collapsed and ended the commodity boom. After 2008, the price fluctuated wildly. At the beginning of 2015, new bubbles were observed for both kinds of prices. The supply and demand conditions are the key factors that resolve the changing trend of oil prices. However, the occurrence of COVID-19 has greatly reduced the oil demand, so the crude oil prices have declined.

Fitting effect analysis of LSTM model
In this section, we describe the use of the daily, monthly and yearly data to measure the short timescale, medium timescale and long timescale performance of the LSTM model, ARIMA model and ANN model. Figure 2 depicts the short-term fitting effect of the ARIMA model. Figure 3 shows the short-term fitting effects of the ANN and LSTM models on the crude oil price. Figure 4 depicts the medium-term fitting effect of the ARIMA model. Figure 5 shows the medium-term fitting effects of the ANN and LSTM models on the crude oil price. Figure 6 depicts the long-term fitting effect of the ARIMA model. Figure 7 shows the long-term fitting effects of the ANN and LSTM models on the crude oil price.

Fitting effect analysis of LSTM model in the short term
We used daily data to measure the short-term performance of the LSTM model, ARIMA model and ANN model. The WTI prices are shown above, while the Brent prices are shown below. Figure 3 shows the short-term fitting effects of the ANN and LSTM models on the crude oil price.
Notes: The upper graph shows the short-term fitting effects for the WTI price, and the lower graph shows the short-term fitting effects for the Brent price. The blue curve shows the real value, while the orange curve shows the fitted price output by the ARIMA model. In the short term, for both kinds of prices, the LSTM model performed much better than the ANN and ARIMA models. Specifically, we mainly compared the fitting effect from three aspects. First, in terms of the trend, from Figure 2, we can learn that the ARIMA model results are not always consistent with the actual value. However, from Figure 3, we can learn that, as for the ANN model and LSTM model, the fitting values have the same trend as the actual values. When the actual price falls, so does the fitting price; additionally, when the actual price rises, so does the fitting price. Second, the differences between the fitting and actual values should be considered. The LSTM model performed the best among these three models, the ANN model ranked second and the ARIMA model was the worst. Specifically, the LSTM fitting value tended to be very close to the actual one, except the extreme values. And, the ANN model has a good fitting effect. Third, in terms of the forecasting performance, when a major turning point of crude oil price occurred, the LSTM model and ANN model was able to fit the changing crude oil price trend well. In 1990 and 1991, the second Gulf War aroused concerns about the supply disruption of crude oil (Ajmi et al., 2021). The concerns caused a sharp rise in the oil prices. Besides that, under the influence of multiple factors such as Organization of Petroleum Exporting Countries (OPEC) production reduction and the recovery of the Asian economic crisis when the oil prices tripled from January 1999 to September 2000. After the 9/11 terrorist attack in the USA, crude oil prices briefly rose because of panic, with Brent crude oil futures reaching USD 31.1 a barrel for a time. Since the middle of January, due to the USA war against Iraq, the crude oil price stopped rising and fell back quickly, with the average price of OPEC crude oil falling below USD 18 per barrel. In early 2003, the third Gulf War broke out. Iraqi oil production stagnated. The political instability and nationwide strike in Venezuela seriously affected the production and export of oil, directly impacting the international oil market. These factors led to drastic fluctuations of the crude oil price. On April 15, 2005, the price of crude oil futures fell in the New York market following the release of the monthly OPEC report stating that it would increase its production capacity considerably. To ease the decline in oil supply caused by natural events such as hurricanes, USA commercial crude oil inventories were sharply reduced. The sharp decline in inventories led to a rise in the crude oil futures price. In addition, continued supply uncertainty in Iraq and Nigeria, as well as several hurricanes in the Gulf of Mexico, brought about a renewed surge in crude oil prices from 2005 to 2008. However, when the global financial crisis happened, the start of a real recession followed and oil prices collapsed. From 2009 onward, the oil prices rebounded along with the recent global economic recovery. From late June 2014 to early 2016, there was a brief and negative mild burst in oil prices, which began just after the OPEC meeting; it lasted more than two months. In addition, the COVID-19 outbreak had a huge impact on the crude oil price; the shrinking demand for crude oil led to surplus crude oil, which applied great pressure on oil storage. Therefore, it caused a sharp drop in the price of crude oil. Overall, the events mentioned above indicated that the LSTM model and ANN model can fit the changing trend of crude oil prices well when a major turning point of crude oil price occurs.

Fitting effect analysis of LSTM model in the medium term
We used monthly data to compare the medium-term forecasting performance among the three models, i.e., the LSTM, ARIMA and ANN models. Figure 4 depicts the medium-term fitting effect of the ARIMA model. The WTI prices are shown above, while the Brent prices are shown below. Figure  5 shows the medium-term fitting effects of the ANN and LSTM models on crude oil price.
Notes: The upper graph shows the medium-term fitting effect on the WTI price, and the lower graph shows the medium-term fitting effect on the Brent crude oil price. The blue curve shows the real value, while the orange curve shows the fitted price output by ARIMA model. In the medium term, for both kinds of prices, the fitting effect of the ANN model was better than that of the ARIMA model, but slightly better than that of the LSTM model. Specifically, from Figure  4, we can learn that, as with the short-term effect, because the ARIMA model is a linear model, it cannot fit the crude oil price sequence well; particularly, it cannot show the volatility of crude oil prices. According to Figure 5, the LSTM model and ANN model perform better. Also, we conducted the analysis from two aspects, i.e., the trends and the differences between the real and fitted values. On the one hand, when we used the LSTM and ANN models, for both kinds of prices, the fitting values were consistent with the real values from the perspective of the trends. When the actual price value increased, the fitting price also increased. On the contrary, when the actual value decreased, the fitted value also decreased. It is worth mentioning that, when a major turning point occurred, the ANN model and LSTM model were able to fit the changing crude oil price trend well. On the other hand, the fitted values from the LSTM and ANN models were very close to the real values. Particularly, the LSTM model was closer than the ANN model. So, we can argue that LSTM and ANNs can be effectively applied to predict the oil prices.  We used yearly data to measure the long-term performance of the ARIMA model, LSTM model and ANN model. Figure 6 displays the long-term fitting effect of the ARIMA model. The WTI prices are shown above, and the Brent prices are shown below. Figure 7 compares the long-term fitting effects of the ANN and LSTM models on the crude oil price. Figures 6 and 7 show that, in the long term, the fitting effect of the LSTM model was much better than that of the ANN model and ARIMA model for both kinds of prices. From Figure 6, we can learn that the ARIMA model was unable to fit the crude oil price sequence well, meaning that it could not show the volatility of crude oil prices. However, from Figure 7, we find that the LSTM model and ANN model performed better in two aspects, i.e., the trend and the differences between the actual and fitted values. On the one hand, as for both kinds of prices, the trends of the real price and fitting price were consistent, and the LSTM model performed better than the ANN model. This is mainly reflected in the fact that, when the actual price increased, the fitted crude oil price also exhibited a rising trend. When the actual price decreased, so did the fitted price. And, the trend of the price fitted by the LSTM model was closer to the real one. Besides that, when a major turning point occurred, the LSTM model and ANN model were able to fit the changing crude oil price trend well. On the other hand, the differences between the actual and fitted values were the smallest among the three models. Therefore, according to what has been discussed above, we can conclude that the LSTM model has strong generalization ability, and that the fitting effect on the crude oil price in different time periods was stable.
Notes: The upper graph shows the long-term fitting effect on the WTI price, and the lower graph shows the long-term fitting effect on the Brent crude oil price. The blue curve shows the real value, while the orange curve shows the fitted price output by ARIMA model.

Forecasting effect analysis of LSTM model
In Section 4, we further investigate the predictive ability of the LSTM model. First, we describe the use of daily, monthly, and yearly data to compare the short-, medium-and long-term predictive ability of the LSTM model. Then, we discuss the results of measuring the predictive ability of the ARIMA model and ANN model. Finally, we compare them with the LSTM model to investigate the predictive ability of the LSTM model. The prediction results of short-, medium-and long-term are shown in Tables 1, 2 and 3, respectively. Table 1 presents the prediction results for the ARIMA, ANN the LSTM models in the short term. Column 2 in Table 1 presents the forecasting methods that were applied to forecast two kinds of prices. Columns 3, 4 and 5 report the MSE, MAE and SDAPE results, respectively. And, the MSE and MAE values were used to reflect the forecasting accuracy, while the SDAPE value was used to reflect the forecasting stability.

Forecasting effect analysis of LSTM model in the short term
From Table 1, we can conclude the following results. In the short term, the LSTM model performed much better than the ANN and ARIMA models in terms of forecasting accuracy. Specifically, from Table 1, we can ascertain the following results. For the WTI price, the MSE (MAE) value of the LSTM model was 0.002 (0.038), which is 100% (50%) and 52392.55 (754.24) times higher than that for the ANN model and ARIMA models, respectively. For the Brent price, the MSE (MAE) of the LSTM neural network was 0.003 (0.045). Compared with the ANN and ARIMA model, the average prediction accuracy of the LSTM model was 66.67% (33.33%) and 439587 (673.8) times higher, respectively. So, we can conclude that the LSTM model can improve the forecasting accuracy for both kinds of prices in the short term. In terms of forecasting stability, for the WTI price, the SDAPE value of the LSTM model was 0.022, which is 40.9% and 679.73% higher than those for the ANN model and ARIMA model, respectively. For the Brent price, the SDAPE value of the LSTM model was 0.034, which is 2.95% and 605.24% higher than those for the ANN model and ARIMA model, respectively. Therefore, for these two kinds of prices, the LSTM model can improve the forecasting stability in the short term. All in all, we can improve the short-term price forecasting accuracy and stability by using an LSTM model. Table 2 shows the medium-term prediction results for the ARIMA, ANN and LSTM models. Column 2 presents the forecasting methods that were applied to forecast these two kinds of prices. Columns 3, 4 and 5 report the MSE, MAE and SDAPE results for the medium term predictions, respectively. From Table 2, we can conclude the following results. On the matter of forecasting accuracy, the forecasting accuracy of the ANN model was higher than that of the ARIMA and LSTM models in the medium term. Table 2 presents the following results. For the WTI price, the MSE (MAE) value of the ANN model was 0.005 (0.064). Compared with the LSTM model and ARIMA model, the average accuracy of the ANN model was higher by 120% (46.88%) and 178503 times (418.23 times), respectively. For the Brent price, the MSE (MAE) value of the ANN model was 0.005 (0.061), which is 80% (44.26%) and 239750 (515.43) times higher than those of the LSTM model and ARIMA model, respectively. All of this reveals that the ANN model can improve the forecasting accuracy for both kinds of prices. Therefore, the ANN model has higher forecasting accuracy in the medium term.

Forecasting effect analysis of LSTM model in the medium term
In terms of forecasting stability, for the WTI price, the SDAPE value of the ANN model was 0.031, which is 41.94% and 424.35% higher than those for the LSTM model and ARIMA model, respectively. For the Brent price, the SDAPE value of the LSTM model was 0.029, which is 27.59% and 487.31% higher than those for the LSTM model and ARIMA model, respectively. These results reveal that, for both kinds of prices, the ANN model can improve the forecasting stability. Therefore, the ANN model is superior for medium-term crude oil price forecasting, and it can improve the medium-term accuracy and stability for crude oil price forecasting. Table 3 depicts the long-term prediction results for the ARIMA, ANN and LSTM models. Column 2 in Table 3 presents the forecasting methods that were applied to forecast both kinds of prices. Columns 3, 4 and 5 indicate the MSE, MAE and SDAPE results for long-term prediction, respectively. Therefore, the LSTM model was able to improve the forecasting accuracy for both kinds of prices. That is to say, the LSTM model had the highest forecasting accuracy in the long term.

Forecasting effect analysis of LSTM model in the long term
In terms of forecasting stability, for the WTI price, the SDAPE value of the LSTM model was 0.134, which is 2.24% and 228.06 times higher than those for the ANN model and ARIMA model, respectively. For the Brent price, the SDAPE value of the LSTM model was 0.076, which is 123.68% and 477.86 times higher than those for the ANN model and ARIMA model, respectively. Therefore, the LSTM model was able to improve the forecasting stability for both kinds of prices. That is to say, the LSTM model performed well in terms of long-term forecasting of the crude oil price, and it was able to increase the forecasting accuracy and stability in the long term.
All in all, the LSTM model had a higher forecasting accuracy than the ARIMA and ANN models during different time periods. The longer the crude oil price forecast timescales of the LSTM model, the lower its forecasting accuracy. Therefore, with longer crude oil price forecast timescales, other factors need to be included in the model.

Conclusions
In this study, utilizing the data on oil prices for the period spanning February 1986 to May 2021, we employed an LSTM model to forecast two kinds of prices. Besides that, the typical ARIMA and ANN models were selected as the comparison models to evaluate the forecasting accuracy and forecasting stability of the LSTM model. From the empirical results, we can come to the following conclusions.
First, the LSTM model has strong generalization ability. And, the fitting effect on crude oil prices was stable for different timescales. On the one hand, in the short or long term, whether it is the WTI or Brent crude oil price, the fitting effect of the LSTM model performs better than the ANN model and ARIMA model. On the other hand, in the medium term, the fitting effect of the LSTM model is much better than the ARIMA model and slightly weaker than the ANN model.
Second, compared with the comparison models, the LSTM model demonstrated higher forecasting accuracy and better forecasting stability for different timescales. On the one hand, the forecasting accuracy and forecasting stability of the LSTM model were higher than those of the ANN and ARIMA models in the short or long term. On the other hand, the forecasting accuracy and forecasting stability of the LSTM model were higher than those of the ARIMA model and slightly worse than those for the ANN model in the medium term.
Third, for the LSTM model, the longer the price forecast timescale, the lower its forecasting accuracy. Therefore, with longer crude oil price forecast timescales, other factors need to be included in the model.
With the better forecasting performance of the LSTM model, it is beneficial for researchers with a deep understanding of the crude oil market. The results also reveal that the LSTM model is suitable for nonlinear and volatile changes in oil prices. Finally, the accurate predictions by the LSTM model also facilitate a deep understanding of the fluctuation mechanism for crude oil prices, as well as of the production operations and investment of enterprises, which can improve domestic economic development and security. Of course, there may be other better methods for crude oil price prediction, but, due to the limitations of personal energy and ability, other improvements to methods could not be implemented. For example, changing the rolling window of the ARIMA model may improve the accuracy and validity of the prediction. The LSTM model also has its disadvantages. It is still a cyclic network, so if the input sequence has 1000 characters, the LSTM unit will be called 1000 times, which is a long gradient path. Although adding a long-term memory channel will be helpful, its capacity is still limited. In addition, due to LSTM being recursive in nature, it cannot be trained in parallel.