The Interpretability of LSTM Models for Predicting Oil Company Stocks: Impact of Correlated Features

Oil companies are among the largest companies in the world whose economic indicators in the global stock market have a great impact on the world economy and market due to their relation to gold, crude oil, and the dollar.This study investigates the impact of correlated features on the interpretability of Long Short-Term Memory (LSTM) models for predicting oil company stocks. To achieve this, we designed a Standard Long Short-Term Memory (LSTM) network and trained it using various correlated datasets. Our approach aims to improve the accuracy of stock price prediction by considering the multiple factors affecting the market, such as crude oil prices, gold prices, and the US dollar. The results demonstrate that adding a feature correlated with oil stocks does not improve the interpretability of LSTM models. These findings suggest that while LSTM models may be effective in predicting stock prices, their interpretability may be limited. Caution should be exercised when relying solely on LSTM models for stock price prediction as their lack of interpretability may make it difficult to fully understand the underlying factors driving stock price movements.

Oil companies are among the largest companies in the world whose economic indicators in the global stock market have a great impact on the world economy [1] and market due to their relation to gold [2], crude oil [3], and the dollar [4].This study investigates the impact of correlated features on the interpretability of Long Short-Term Memory(LSTM) [6] models for predicting oil company stocks.To achieve this, we designed a Standard Long Short-Term Memory (LSTM) network and trained it using various correlated datasets.Our approach aims to improve the accuracy of stock price prediction by considering the multiple factors affecting the market, such as crude oil prices, gold prices, and the US dollar.The results demonstrate that adding a feature correlated with oil stocks does not improve the interpretability of LSTM models.These findings suggest that while LSTM models may be effective in predicting stock prices, their interpretability may be limited.Caution should be exercised when relying solely on LSTM models for stock price prediction as their lack of interpretability may make it difficult to fully understand the underlying factors driving stock price movements.We have employed complexity analysis to support our argument, considering that financial markets encompass a form of physical complex system[?].One of the fundamental challenges faced in utilizing LSTM models for financial markets lies in interpreting the unexpected feedback dynamics within them.

I. INTRODUCTION
Machine Learning, which is one of the subfields of Artificial Intelligence, has its applications in various fields including Economics, Medicine [7], Cosmology [8], Photonics [9], Robotics [10],IoT(Internet of Things) [13] and etc.Long Short-Term Memory (LSTM) models are widely used in the financial industry for time series prediction, including stock prices.LSTMs are known for their ability to capture complex patterns in sequential data.However, one major limitation of LSTM models is their lack of interpretability.That is, it is often difficult to understand how the model arrives at its predictions and what factors are driving the results.Despite their lack of interpretability, the performance of LSTMs in predicting stock prices has been well-documented in previous research [11], [12].Therefore, while caution is necessary when relying solely on LSTMs for financial decisions, these models can still be useful in predicting the future price movements of stocks.
It is widely acknowledged that oil companies occupy the largest market share in the energy industry [19].These companies have enormous global reach and wield substantial influence in the world economy.In fact, oil is arguably the most vital factor of the global economy, as the imposition of sanctions on the export or import of oil from many countries can practically paralyze their economies, especially for those countries with oil-dependent economies, such as the Persian Gulf countries [15].Additionally, stock indices of oil companies are regarded as among the most important indicators in the global stock market, with correlations between the shares of oil companies, gold, the US dollar, and crude oil, all of which have a significant impact on the market [16].
Neural Networks, despite their lack of interpretability, have proven useful in modeling oil companies.Long Short-Term Memory(LSTM) neural networks are one of the most powerful architectures in Recurrent Neural Networks.They have addressed the problem of gradient vanishing in recurrent neural networks [17], thereby allowing more accurate predictions of the stock market [18].This market behaves like an unstable dynamic system, characterized by numerous non-linear correlations.Accordingly, researchers have proposed various methods to predict its behavior.
To review the literature oil research path, we can mention Alvarez-Ramirez et al. work [14] which analyzed the auto-correlations of international crude oil.After carrying out several tests, in 2005, Moshiri and Foroutan [25] concluded that oil stock markets have a recursive architecture because they are time series.They used three methods ANN, GARCH, and ARMA, and the best results come from the ANN method.
Author in [26] published an article using Multilayer Neural Networks, which examined the relationship between crude oil prices and current prices.Moreover, they showed that the future prices of crude oil contain new information about oil spot price detection.Ye et al. [27] studied the changing relationships between the prices of crude oil and several other factors from January 1992 to December 2007 by the Short-Run Crude Oil Price Forecast Model.
Chen and colleagues developed a model based on deep learning and used this model to model the unknown non-linear behavior of WTI stocks [29].QI, KHUSHI, and POON used different recursive neural network architectures including LSTM, GRU, BiLSTM, RNN to model the Forex market and obtained significant results from these models to predict several currency pairs.They used a database that relates to ELLIOT method information, one of the stock market forecasting methods [30].
In 2018, Gupta and Pandey predicted crude oil prices by using LSTM network [31], and following that Cen and Wang applied deep learning algorithms to anticipate the volatility behavior of crude oil prices [32].To solve the chaotic and nonlinear features of crude oil time series Altan and Karasu used a new crude oil price prediction model is proposed in this study, which includes the long short-term memory (LSTM), technical indicators [34].
In 2017, Arfaoui and Rejeb published an article examining the effects and relationships of stock markets, oil, dollars, and gold based on global market documentation.They concluded that oil prices are significantly affected by stock markets, gold, and the dollar and that there are always indirect effects, which also confirms the presence of correlations in the global market [35].In this paper, we compare this correlation feature and the relationships between stocks with the dollar, crude oil, gold, and major oil company stock indices, we create datasets and compare the results of forecasts with real data.This [20] article dives deep into the challenges posed by LSTM models in financial market forecasting.Smith et al. discuss the concept of "black box" models -LSTM architectures that lack transparency in their decision-making process.By examining the weights, biases, and internal mechanisms of LSTMs, the authors ascertain the difficulties in understanding and interpreting these models, especially in financial contexts.They emphasize the need for interpretability, highlighting potential risks and the consequences of solely relying on uninterpretable LSTM models.
Johnson, et al. tackle the enigma of LSTM interpretability within the financial markets domain.They discuss the challenges of interpreting LSTM models specifically for financial forecasting.The authors emphasize the importance of explaining predictions and making sense of underlying patterns and features to build trust in financial decision-making.The article provides a holistic overview of conceptual and technical difficulties, articulating the limitations of LSTM models in this context [22].
Brown et al. delve into the intricate aspect of feature importance within LSTM models.They argue that understanding which features are most influential in driving predictions is vital for financial market forecasting.The article explores various techniques and approaches that attempt to unravel the complexity of feature transformations within LSTMs.By illuminating the challenges of achieving feature importance analysis, the authors call for further research to address the uninterpretability of LSTM models [23].
LSTM is a dynamic network that is used to predict these markets due to the dynamic nature of energy financial markets.The transparency of this algorithm in detecting suprising based on stochastic distortion [24] is a fundamental challenge for investors.Considering the importance of oil company stocks for investors, checking the transparency of this algorithm can be significant.Considering that there are various causes for fluctuations and disruptions in the markets of oil companies, the investigation of the main economic factors in the comparative impact of these stocks can be of great help in modeling.The purpose of this article is to investigate the effect of these main economic factors that have correlation with the stocks of major oil companies and to investigate the effect on the interpretability for regression with LSTM.These articles collectively establish the significance of interpretability in LSTM models for financial market forecasting.They consistently highlight the limitations and potential risks of relying solely on uninterpretable LSTM models and advocate for the need to strike a balance between accuracy and interpretability.This article is structured as follows: First, we investigate the complexity of the relationships between stocks through discrete correlation analysis.Subsequently, we design a standard LSTM network, optimize its hyper-parameters, and then perform modeling.Finally, we review the analysis and modeling results and draw conclusions.

II. OIL SHARES AND COMPLEXITY OF STOCKS RELATIONS
The relation between oil companies' stocks on one hand and the prices of other assets like gold, crude oil, and the price of the US dollar, on the other hand, is intrinsically interesting for many economical and political reasons.Before calculating the complexity, it has worth having a short introduction for oil companies.

A. Oil companies
In the global economy, large companies operating in the field of energy and oil are among the most authoritative companies in the global economy.Companies such as Total, BP, Cairn Energy, Schlumberger are among the most authoritative companies.These companies are trading in energy and oil and their investors and shareholders are among the largest investors and shareholders in the world, for whom the trend of changing the indicators of these companies in the stock market is very worthful.Moreover, the strong dependence of industry [21] in various fields on oil has made oil a major factor influencing the policies of each country.In the following, we introduce some of these companies which we analyze their shares in this paper.WTI: One of known light sweet crude oil is West Texas Intermediate (WTI) which refers as one of the main global oil benchmarks.WTI has hight quality is easy to refine and is sourced primarily from inland Texas.BP.L: BP plc is a British multinational oil and gas company based in London, England.It is one of the world's seven oil and gas companies.
FP.PA: TotalEnergies SE is a French multinational unified oil and gas company which is established in 1924 and is one of the seven major oil companies.SLB.PA: Schlumberger Limited is an oil field services company whose member have more than 140 nationalities working in more than 120 countries.Schlumberger executive offices are located in Paris, Houston, London, and The Hague.

B. Correlation between shares and economic stocks
The crude oil index is the most important characteristic in determining the index of oil companies.The sale of crude oil in the world market is done in dollars.Commonly, the dollar can change the value of the indexes of oil companies.Moreover, the gold value can cause changes and fluctuations in currency indices.Their effects on each others can be obtained by calculating the correlation coefficient between their data [35].In this article, the value of the stock indices that we have examined, from 08/03/2009 to 07/01/2021, the results of the correlation calculation are shown in the table (I): This table is represented as an array where its principal diameter is equal to one, and the other component represents the correlation coefficient between the value of stock indices introduced in the global market.
To have a better presentation, we draw the Heatmap diagram which is a type of information visualization (data visualization) in which the value of each cell of the matrix input is displayed in one color.The correlation coefficient obtained in the previous part is shown in the diagram of the thermal map below Fig. (1).The lighter the color, the more direct the relationship and the higher the direct correlation, and the darker color, the higher the inverse relationship and correlation.

C. Discrete correlation analysis for oil shares
To conduct a detailed analysis of the relationships between WTI, USD, and GOLD with shares of TOTAL, BP, Schlumberger, and Cairn Energy oil companies, we discretized the data and then examined the Pearson correlations between them.Between 2013/6/24 and 2021/4/7, we discretized around 2000 data points for each stock into 50 40-day data sets.
The FIG( 2) below presents the discrete correlations of the BP company data set with WTI, USD, and GOLD data sets.
The correlation histograms of the BP stock index with the WTI, USD, and GOLD stock indices are displayed in FIG( 3).The histograms are divided into four columns based on the results of the correlation analysis, as shown in Table(II).The statistical parameters, including the average, median, variance, and standard deviation, for the correlations between the BP stock index and the WTI, USD, and GOLD are presented in Table(III) and illustrated in Fig( 4).The discrete correlations between the Total company data set and the WTI, USD, and GOLD data sets are displayed in FIG.(5).
The correlation histograms of the Total stock index with the WTI, USD, and GOLD stock indices are presented in FIG (6).The histograms are divided into four columns based on the results of the correlation analysis, as shown in Table(IV).
The statistical parameters, such as the average, median, variance, and standard deviation, for the correlations between the Total stock index and the WTI, USD, and GOLD are displayed in Table(V) and Fig (7).The discrete correlations between the Cairn Energy company data set and the WTI, USD,

III. LSTM ARCHITECTURE FOR OIL PRICES
Long Short Term Memory, LSTM is an architecture for RNNs to avoid the gradient vanishing problem in RNNs in memory building.LSTM architecture has three gates, forget gate, input gate, and output gate as shown in Fig. (14).LSTM can read, write and delete information from its memory.The LSTM structure has the capability to identify which cells are stimulated and compressed based on the previous state, available memory, and current input.
Forget gatedetermine what information data we're going to throw away from the cell state.In this gate, information is deleted or stored based on the output of the sigmoid function.This gate cell is formulated as follows: x t : Input, b : Bias, i t : Inputgate, c t : Cellstate, o t : Outputgate (2) Input gate determine what new data we're going to store in the cell state.The input gate is actually a gate for writing memory which is represented as Cell state drops the information about past subjects and adds new information as follows Output gate decide what we're going to output and reading from Memory which is formulated as

A. Data and Features
In this paper, we use four major (open, high, low, and closing prices) Oil stock pairings-FP.PA (Total), CNE.L (Cairn Energy), BP.L (BP), SLB.PA (Schlumberger) with their daily interval data and use for comparison stock pairings-WTI, gold, dollar with their daily interval data from 2009/8/14 to Sep 2020/7/19 for training and data from 2020/7/20 to 2021/7/15 for testing.Data was extracted from Alpha Vantage API.[37] This section provides a summary of the findings obtained through experiments conducted using our proposed methodology.The neural network model utilized was the LSTM network, implemented using the Python Neural Networks library and Keras, running within the TensorFlow 2.0 Python development environment to train the data.

B. Hyper-parameter selection and Network topology
The fundamental determination of hyper-parameters for the neural network has a very important effect on the modeling results.appropriatenumber of time lags is one of the most important hyper-parameters that has a very important effect on the results in modeling with recurrent neural networks.Autocorrelation is a statistical method used to measure the relationship between a time series data point and its lagged values.It indicates whether there is a correlation between data points that are a certain distance apart in time.Autocorrelation can be used in the context of Long Short-Term Memory (LSTM) models to find the appropriate number of time lags to use for prediction.In LSTM models, the previous time steps are used as features for predicting the next time step.One of the key challenges is to determine the appropriate number of time lags to use for prediction.If too few lags are used, important features may be missed, leading to poor performance.If too many lags are used, the performance may also suffer due to overfitting.Autocorrelation can be used to address this challenge by measuring the correlation between the time series data point and various lagged values.By plotting the autocorrelation function, we can determine the optimal number of lags to use for prediction.In general, the autocorrelation function declines as the lag increases, with the most significant lags occurring at the beginning of the time series.Basic determination of this value prevents.The results of the Autocorrelations of the close price of each stock from 2013/6/23 to 2017/6/12 with each of the dates in Fig. (15), Fig. (16), Fig. (17) and Fig. (18)are as follows: Due to the fact that in the (II C) section, we have discretized the data as 40-day packages and then performed the Autocorrelation analysis, and according to Fig. (15), ( 16), (17), and (18), we can see that the data has a strong direct relationship with the future 40 days.According to the obtained results, we set the value of the appropriate number of time lags equal to 40, so that we can check the interpretability of LSTM for predicting the data of oil stocks based on the results obtained from the modeling and the results of the (II C) section.Adam's [36] optimization function is used with 0.0005 learning rate, 10 percent data is with LSTM, these values are the same.
For modeling, we have used a simple standard LSTM topology, which is displayed in Table(X).

C. Evaluation Measures
To measure the badness of the model, people use Mean Square Error (MSE), Root means square error (RMSE), Mean Absolute Error (MAE), and Mean Absolute Percentage Error (MAPE), as defined below: For measuring the average of the squares of the errors, MSE measure can be used which is defined as the following formula: To measure the average root of the squares of the errors we use RMSE which is defined as: which describes how spread out these residuals are by the standard deviation of prediction errors.To measure the average of absolute error we use MAE which calculates errors between pair observations.It is defined as: Finally, to measure the size of the error in percentage terms we use MAPE which is calculated for the mean of the absolute percentage errors of prediction.It is defined as the following formula: Now, we are in the position where we can apply these evaluation measures as error metrics in our prediction.

IV. DISCUSSION
In this study, we have demonstrated the potential of deep learning as a tool for forecasting stock prices in the oil industry, either as a replacement or a complement to traditional forecasting methods.
We began by investigating the correlation coefficients between the stocks of various oil companies, as well as the USD, WTI crude oil, and gold indices.We then discretized the stock data and performed discrete correlation analysis.
In Sec.(II B), we observed that there is a correlation between the stocks of the oil companies in question and the gold, dollar, and crude oil indices.Based on the findings presented in Table (I), we obtained the following results: Overall, our analysis suggests that there are significant correlations and relationships among the stock indices of the oil companies, as well as with the USD, WTI, and gold indices.Specifically, BP and Cairn Energy stock indices show strong direct relationships with each other, while TOTAL appears to be more inversely correlated with gold.Schlumberger has weaker correlations with the other indices, but exhibits a strong direct relationship with TOTAL and weak direct relationships with BP and Cairn Energy.Our findings suggest that deep learning algorithms may be particularly useful in predicting stock prices within the oil industry given these complex interrelationships and correlations.
Secondly, in order to verify the accuracy and stability of the results obtained from Section (II B), and prior to modeling and checking the results of the LSTM model, we will examine the results of Section (II C) which presents a discrete analysis of the correlations.
Secondly, in order to verify the accuracy and stability of the results obtained from Section (II B), and prior to modeling and checking the results of the LSTM model, we will examine the results of Section (II C) which presents a discrete analysis of the correlations.
• According to Fig. (2), BP shares display fluctuations in their correlations with the index of gold, USD, and WTI stocks throughout abnormal correlation intervals, which are not confined to specific correlation intervals.In Fig.
(    • In Table (XII), it was observed that incorporating the crude oil and dollar indices did not decrease the cost function.However, during the learning process, when the machine analyzed the gold index, it significantly improved the measurement and resulted in reduced costs, thereby helping us better our modeling, as depicted in the Cairn Energy diagrams in Fig. (20).• Table (XIII) indicates that the WTI index resulted in an increase in the cost function, and the addition of the gold and dollar indices made no significant impact on the learning process.The diagrams for the Schlumberger company are illustrated in Fig. (21).In general, the presented results show that the range of errors for each stock varies among different models, though these differences are consistent across all stocks.Based on our analysis, it can be concluded that the use of correlated features did not improve the performance of the LSTM model for the oil market.
Our findings revealed that although LSTM models could achieve high accuracy in predicting stock prices, their interpretability was limited.Specifically, their internal states and weight parameters were difficult to interpret and could not provide clear insights into the underlying factors driving stock price movements.Overall, caution should be exercised when relying solely on LSTM models for stock price prediction, as their lack of interpretability may make it difficult to fully understand the factors driving stock price movements.Further research is needed to improve the interpretability of LSTM models for predicting stock prices.

TABLE I :
Correlations between Shares.

TABLE VII :
Schlumberger discrete correlations statistical parameters .

TABLE X :
This table illustrates the network topology which includes each layer along with neurons and computational parameters.
3) and Table (II), around 30 percent of the correlations exhibit weak direct relationships with WTI, which contradicts the results of Table (I), whereas approximately 40 percent show a strong direct association.About 36 percent of the correlations indicate an inverse relationship with the USD, which is contrary to Table (I), but around 64 percent of the correlations demonstrate a strong direct relationship with the USD.Approximately 46 percent of the correlations suggest an inverse relationship with gold, while about 54 percent of the correlations demonstrate a direct relationship with gold, which contradicts the findings of Table (I).The average correlation of BP shares with the WTI stock index is 0.27, indicating a weak direct association, which is consistent with the results of Table (I).However, this average has a standard deviation of 0.45, representing high dispersion.The median value of 0.32 is noteworthy, acting as the intermediary between the outcome obtained from Table (I) and the average of the correlations, thereby indicating that the correlations with an inverse relationship carry more weight.This may suggest the influence of indirect factors such as political events.The average correlation of BP's shares with the gold stock index almost indicates a lack of relationship and negative correlation, which contradicts the findings of Table (I).The median value is smaller than the average, indicating that the correlations outweigh the inverse relationship between the two stocks.The average correlation of BP shares with the dollar suggests a weak direct relationship, contradicting the results of Table (I).Moreover, the average of these correlations highlights the weight of the correlations with a direct relationship.
(19)e (IV), roughly 60 percent of the correlations demonstrate a direct relationship between TOTAL shares and the stock index and WTI, which contradicts the results of Table (I).About 56 percent of the correlations exhibit a direct relationship between TOTAL shares and the USD, which contradicts the findings of Table (I), but in terms of gold, it confirms the results of Table (I).The median correlations of TOTAL shares with the USD and gold are approximately zero, which aligns with the results of Table (I) in the case of USD shares, but in the case of gold, it contradicts the outcomes of Table (I).This is an essential point.Based on the standard deviation value, there is a high dispersion among the correlation values.The average and median correlations of this stock with WTI are consistent with the results of Table (I).•Based on Fig. (9) and Table (VI), approximately 70 percent of the correlations imply a direct relationship between Schlumberger company shares and WTI shares, matching the results of Table (I).About 56 percent of the correlations suggest a direct relationship between Schlumberger shares and the USD, while roughly 52 percent of the correlations contradict the outcomes of Table (I) regarding their relationship with gold stocks.The mean correlations in Table (IX) for Schlumberger stocks with WTI show a weak direct relationship.The mean and average of these shares with gold stocks are both zero, which contradicts the results of Table (I).Furthermore, concerning the mean and median of these shares with the USD, it indicates a greater weight of correlations that demonstrate a direct relationship.•BasedonFig.(12) and Table (VIII), around 72 percent of the correlations indicate a direct relationship between Cairn Energy shares and WTI, consistent with the outcomes of Table (I).About 70 percent of the correlations demonstrate a direct relationship between these stocks and the USD, contradicting the results of Table (I), which suggested an absence of a relationship.Roughly 52 percent of the correlations suggest a direct relationship between Cairn Energy shares and gold shares, contradicting the outcomes of Table (I).The median and average correlations of Cairn Energy shares with the USD imply a weak direct relationship, differing from the results of Table (I).The mean and average of these shares with gold show a contradiction with the outcome of Table (I) by indicating a lack of a relationship.Also, the mean and average correlations of these stocks with WTI demonstrate a direct relationship, aligning with the results of Table (I).Based on the results obtained from the discrete analysis of correlations, we can observe that the correlation outcomes are not always consistent and do not necessarily increase within a specific correlation interval.Instead, they fluctuate across different correlation intervals.In the oil markets, various factors like political decisions, shifts in politics, and conflicts impact the price, which changes over time.Third, to forecast stock prices of different companies, we employed Recurrent Neural Networks with LSTM architecture, given that these stocks exhibit changes in time series.We conducted empirical experiments and performed on the stock indices dataset to evaluate the predictive performance in terms of several common error metrics, namely MSE, MAE, RMSE, and MAPE.Here are the summary results based on these metrics:• In Table (XI), it was observed that including the WTI (crude oil), gold, and dollar indices did not enhance the model's prediction and did not lessen its errors (as seen in the error metrics).Furthermore, the same four primary features had the lowest cost function.The empirical analysis results for BP are illustrated in Fig.(19):

TABLE XII
FIG. 20: (Cairn Energy Real Prices vs Predicted Prices)

TABLE XIII
Table (XIV) regarding Total Shares reveals that none of the WTI, dollar, or gold indicators enhanced the learning process, as evidenced by Fig. (22).

TABLE XIV
FIG. 21: (Schlumberger Real Prices vs Predicted Prices) FIG.22: (Total Real Prices vs Predicted Prices) V. CONCLUSION