# Multilayer Graph-Based Deep Learning Approach for Stock Price Prediction

Authors: Mohammed Ali Alshara
Journal: Security and Communication Networks
 (2022)

---

## Abstract

Although a strategy for predicting stock prices using relational data has been described recently, no practical way for selecting aggregating various forms of relational data to forecast stock prices has been discovered. The authors present an upgraded multilayer node graph attention network (FHAN) model that incorporates the Fraudar algorithm and provides insight into the interaction between several items. The model, which regards businesses as nodes and interactions as edges, aggregates data from various connection types and adds it to each company’s node representation, which is then automatically fed into the task-specific layer select information. The testing findings indicate that this approach is more accurate in stock price prediction than the currently popular neural network methodology. The experiment compares several distinct neural network algorithms. This approach is more accurate than the previous method when ideal parameters are used. The average rise is around 4%, while the largest increase is 24%.


---

## Body

## 1. Introduction

Predicting stock market movement remains a difficult topic, and many experts, both in business and academia, have been interested in predicting the stock market’s future trend for a long period of time. In the financial business, researchers who specialize in identifying profit trends in historical data are referred to as quantitative practitioners. They increasingly utilize systematic trading algorithms to automate trading choices. Although there is considerable debate in academia, several research studies have demonstrated that the stock market may be approximated to a certain extent. According to value investors, a company’s stock price should correspond to its inherent worth. If a company’s stock price is now less than its intrinsic value, investors should purchase it since the price will ultimately converge with the underlying value. The fundamental analysis of a business entails an in-depth examination of its performance and profitability, and the intrinsic worth of the business is determined by the influence of its product sales, employee value, infrastructure, and investment profitability. Stock prices are viewed by quantitative researchers as typical time series data with complicated patterns. Through adequate preprocessing and modeling, the design may be analysed and useful information is collected. Technical analysis is mostly based on closing prices and trading volume. The stock price fluctuates randomly and nonlinearly.Technical analysis is concerned with the extraction of relevant characteristics from raw data. Technical indicators are components generated from these data in the financial sector. These components include adaptive moving averages, relative strength indices, stochastic, and momentum oscillations. The act of obliterating relevant technological indications is analogous to feature engineering. Numerous research studies have demonstrated the effectiveness of a stock volatility prediction model based on recurrent neural networks. Stock forecasting approaches based on text try to capture investors’ perspectives on events. This style of research presupposes that the stock price of a firm is equal to the total of investors’ opinions about the company.The community is extremely interested in harnessing the power of graph-structured data. Literature [1] proposed a method for stock market forecasting using company relational data. Literature [2] proposed a more general framework with long short-term memory (LSTM) autoencoding. Literature [3] also proposed a GNN model that can capture the temporal characteristics of stocks using a variety of different types of relations in public knowledge databases. Literature [4] established a company network based on financial investment information. The performance of the prediction is compared with that of classic network embedding models. The LSTM framework structure is the most often used framework structure in time series modeling. The present literature makes use of LSTM as a module for feature extraction. Literature [5] detailed the process of extracting node feature vectors from raw pricing data. Literature [6] presented the Fraudar technique, which is based on a global measure G that may be used to describe nodes’ average suspicious degree. According to the available research, there are few approaches for considering relational network and node information features in terms of graph representation. Traditionally, approaches such as employing classical PCA for dimensionality reduction, including nonlinear dimensionality reduction, would first input the matrix according to the graph’s network information. LLE [7], a Laplacian algorithm based on widely accepted assumptions [8], and directed graph approaches [9]. Given an adjacency matrix, the LLE algorithm depicts each node as a linearly weighted neighboring node, calculates the node’s rebuilt weight matrix, and then transforms it to an eigenvalue solution. The Laplacian algorithm uses the graph’s adjacency matrix to calculate the eigenvalues and the eigenvectors corresponding to the minor k non-zero eigenvalues as a graph to ensure that the graph is correct. After dimension reduction, adjacent nodes in the chart are mapped to their spatial positions using the eigenvectors corresponding to the minor k non-zero eigenvalues as a graph. Literature [10] communicated information between connected nodes using a graph-based learning viewpoint. By embedding node characteristics in the matrix decomposition process, relationship information and node features are incorporated into the process of learning node representations. Literature [11] combined node classification and graph representation problems using a semisupervised learning technique although this method is limited to node classification tasks. Although current approaches include relational data into stock market forecasting models, there is still much opportunity for improvement. No study has been conducted to determine which type of relational data is more advantageous for forecasting stock movements, nor has an effective mechanism for selecting aggregating information of various relational types been discovered. Additionally, earlier work has concentrated on node categorization. The two primary goals of graph-based learning are node classification and graph classification. In a stock market network, a single node often represents a firm, and forecasting the future movement of individual stocks is analogous to a node classification problem.This article suggests that nodes may be used to represent update functions in graph classification problems. How to leverage various types of relations and investigate their effects on business stock price movements using graph-based learning methods and relational data successfully in stock market forecasting. Relevant information might lower the predictive accuracy.This paper draws on the idea of literature [12] and adopts the unique stock prediction method [13] and the attention layering mechanism [14]. Similar to the research node classification task, based on the Tensorflow [15] platform and Wiki database [16], from the fusion relationship from the perspective of network information and node features, a new multilayer node graph attention network (FHAN) method is proposed using the meta-path [17] method. Experimental data show that the FHAN way in this paper has better performance in stock price prediction than other neural network models and LSTM-attention [18]. References [19, 20] presented a novel Convolutional, BiGRU, and Capsule network-based deep learning model, HCovBi-Caps, to classify the hate speech, and multichannel CNN modeling is discussed in [21–23] and a new multichannel convolution neural network (MCCNN) model is proposed for extracting the relationship.


## 2. FHAN Stock Price Prediction Model

### 2.1. The Overall Framework of the Prediction Model

Figure1 shows the overall framework of FHAN that integrates various modules, which can selectively aggregate information from different relationships and add this information to the company’s nodes. The FHAN model starts from the original node and uses LSTM to extract initial features from the feature module. In this paper, the Fraudar algorithm is embedded in a multilayer graph network for the first time. The purpose is to extract more accurate relationship data from company node features, eliminate those companies with high suspicious degrees, and retain node data of companies with low suspicious degrees to enter the relationship building. The module layer, in the randomly generated walk path, uses a truncated random walk to generate a large number of paths from the graph to exchange information between adjacent nodes. At the same time, the attention module is shared, and the calculation of attention scores can be calculated in parallel according to nodes and meta-paths. The hierarchical graph attention network scores according to the attention weights at each layer, selects important information, adds input to the task-specific individual stock price prediction layer, and completes the whole stock price prediction process.Figure 1
FHAN general framework.


### 2.2. Feature Extraction Module

The feature extraction module is used to portray the enterprise’s current status using the historical pattern of stock price [22] volatility. LSTM is employed as a feature extraction module in this investigation. The LSTM model is used to solve time series issues because it can make full use of the whole sequence information, including the relationships between multiple firms, and process each node using this relationship. Each cell in an LSTM consists of an input gate, an output gate, a forget gate, and a memory cell.


### 2.3. Fraudar

Fraudar is often used in relational network antifraud, mainly to identify suspected fraudulent users. The algorithm defines a global metric G that can express the average suspicious degree of nodes. In the iterative process of gradually greedily removing nodes with the least suspicious degree, the remaining nodes make G reach the most effective form the dense subgraph with the highest questionable degree. Define the number of company node sets S, G(S) = F(S)/S, where F(S) is the sum of the suspicious degrees of nodes and G(S) can be understood as the questionable degree of each node in the network structure. When a node with a high suspicious degree is added to the network, the percentage of increase in F(S) brought by it is greater than the percentage of increase brought by S, and G(S) increases; when a node with a low suspicious degree is added, it gets the rate of growth in F(S) less than the increase brought by S, and G(S) decreases at this time; so G(S) is a practical expression of global suspiciousness. The suspicious degree of a node is, in turn, the sum of the questionable degrees of the edges it is connected to. The more advantages related to a node, the less suspicious it is; the weight is reduced according to the number of connections. The practical calculation formula of edge suspiciousness is 1/log(x + 5), where x is the number of edges. The actual meaning is that the more complex the relationship network information is, the less suspicious it is. The purpose is to extract these less suspicious company nodes; generally, these companies are listed companies with high reputations. At the same time, those company nodes with a high degree of suspicion and few edges connected to the nodes are excluded, which are not conducive to predicting the stock price, which is the so-called noise.After the initial suspicious degree is determined, in the model iteration process, Fraudar greedily removes all nodes with the lowest suspicious degree step by step. However, each iteration traverses all nodes to locate the minimum value, which is very expensive. For this purpose, a priority tree is constructed as shown in Figure2, and the parent node records the minimum value of its child nodes, so as to start from the global minimum value recorded by the root node, and you can quickly locate the leaf node corresponding to the minimum value and then delete it. At the same time, the suspicious network degree and priority tree are updated, and the global average questionable degree G(∗) of the remaining nodes increases gradually. When all node iterations have been removed, backtrack this process until G(∗) reaches the maximum iteration. The corresponding retained node is the target node, and the relationship network between them is the high-density subgraph of the entire network.Figure 2
Priority tree.


### 2.4. Relational Modeling Module

If node JV appears in the neighbor window of node vi in a randomly generated walk route on G with a specified window size k, they are neighbor nodes as long as node vi reaches VJ within k steps. Numerous pathways are generated from the graph using a truncated random walk. Each neighboring node is produced in this manner, and information between adjacent nodes is shared utilizing the graph neural network’s primary function. The data from neighboring nodes are aggregated and added to the representation of each node, effectively merging information from various node and connection types. Each layer of the structured network is meant to convey the significance of neighboring nodes and relation kinds. The final node representation combines the learned vector with its node characteristics and acts as a graph representation for the learned input vector. The graph representation algorithm is as follows:Algorithm 1: Node relationship modeling algorithm.
Input: graph G (V, E) node feature vector fi, random walk length a1, slidingOutput: the size of the moving window (a2), the number of times each node travels (a3), the node represents the vector dimension (d), batch size (b), and gradient update step c;(1)
Randomly initialize the node representation vector w(2)
D ⟵ (G,a1,a3) a2(3)
While does not converge do(4)
Batches⟵ConstgructBatch (D,b)(5)
For each batch B in Batches do:(6)
∇w=0(7)
for each sample (vi, vj,λ) in B do(8)
∇ wi ⟵ ∇ wi + ∂L∂wi(9)
End for(10)
W⟵w−c∇w=0(11)
End for(12)
End while


### 2.5. Specific Task Module

After updating the node representation using relational modeling, the node representation will be fed back to a specific task module. Node representations can be used in different tasks with appropriate models. This study conducts experiments on a graph-based learning task: individual stock prediction.FHAN: comparing companyi in the feature extraction module at time the f-dimensional feature vector is denoted as eti ∈ Rf. Edges can be defined between different types of relationships. The target node i and the set of adjacent nodes need to be known from each relation type for neural graph networks. Put the neighbor i in relation type demoted as Nirm, while denoting the embedding vector of relational m as erm ∈ Rd. d is the dimension of the relational embedding vector. Hopefully, the model will filter out some of the noise, as companies have many different types of relationships, and some information is irrelevant to forecasting stock price movements.


### 2.6. Attention Mechanism Layer

Attention processes are frequently utilised to assign a weight to particular pieces of information. Our stock prediction hierarchical attention network (FHAN) chooses only important information at each level using a hierarchically built attention mechanism. As seen in Figure3, FHAN picks critical information of the same relationship type from neighboring nodes in the first layer. The attention mechanism is utilised to determine the current weight differences between adjacent nodes. To calculate these attention scores, the relational embedding vector erm and node representations i and j are concatenated into a vector, denoted as Xijrm∈R2f+d; the attention score is calculated as follows:(1)Vij=XijrmWs+bs,aijrm=expVij∑​expVik,k€Nirm,where Ws and bs are learnable parameters used to compute the attention score, this formula is used to calculate the attention weight value, and all weighted node representations are combined to calculate the company’s relationship vector representation m. Selectively information is gathered from specific relationships of neighboring nodes. The vector srmi contains the primary information from the relation vector m. The representation of industry relationships summarizes the overall industry status of the target company, and our model should prioritize transaction decisions based on aggregated information for each connection. The second layer of FHAN uses another attention mechanism to assign weights to information continuously. The vector srmi containing the primary information representing the situation of the current company ei, is input to the relevant attention layer with the relational embedding vector erm with xirm∈R2f+d.(2)Virm=XirmWr+br,airm=expVirm∑expVirk.Figure 3
Accuracy of training dataset on different models.


### 2.7. Stock Forecast Layer

Classify stock price movements by two types of labels: up and down. For the individual stock preselection task, a linear transformation layer is added:(3)Yi=softmaxeiWpn+bpn.Among them,Wpn∈Rd×l,bpn∈Rl; this paper uses the cross-entropy loss to train the company-related data model.(4)Lossnode=∑i∈Zu∑c=1lYiclnYic.


## 2.1. The Overall Framework of the Prediction Model

Figure1 shows the overall framework of FHAN that integrates various modules, which can selectively aggregate information from different relationships and add this information to the company’s nodes. The FHAN model starts from the original node and uses LSTM to extract initial features from the feature module. In this paper, the Fraudar algorithm is embedded in a multilayer graph network for the first time. The purpose is to extract more accurate relationship data from company node features, eliminate those companies with high suspicious degrees, and retain node data of companies with low suspicious degrees to enter the relationship building. The module layer, in the randomly generated walk path, uses a truncated random walk to generate a large number of paths from the graph to exchange information between adjacent nodes. At the same time, the attention module is shared, and the calculation of attention scores can be calculated in parallel according to nodes and meta-paths. The hierarchical graph attention network scores according to the attention weights at each layer, selects important information, adds input to the task-specific individual stock price prediction layer, and completes the whole stock price prediction process.Figure 1
FHAN general framework.


## 2.2. Feature Extraction Module

The feature extraction module is used to portray the enterprise’s current status using the historical pattern of stock price [22] volatility. LSTM is employed as a feature extraction module in this investigation. The LSTM model is used to solve time series issues because it can make full use of the whole sequence information, including the relationships between multiple firms, and process each node using this relationship. Each cell in an LSTM consists of an input gate, an output gate, a forget gate, and a memory cell.


## 2.3. Fraudar

Fraudar is often used in relational network antifraud, mainly to identify suspected fraudulent users. The algorithm defines a global metric G that can express the average suspicious degree of nodes. In the iterative process of gradually greedily removing nodes with the least suspicious degree, the remaining nodes make G reach the most effective form the dense subgraph with the highest questionable degree. Define the number of company node sets S, G(S) = F(S)/S, where F(S) is the sum of the suspicious degrees of nodes and G(S) can be understood as the questionable degree of each node in the network structure. When a node with a high suspicious degree is added to the network, the percentage of increase in F(S) brought by it is greater than the percentage of increase brought by S, and G(S) increases; when a node with a low suspicious degree is added, it gets the rate of growth in F(S) less than the increase brought by S, and G(S) decreases at this time; so G(S) is a practical expression of global suspiciousness. The suspicious degree of a node is, in turn, the sum of the questionable degrees of the edges it is connected to. The more advantages related to a node, the less suspicious it is; the weight is reduced according to the number of connections. The practical calculation formula of edge suspiciousness is 1/log(x + 5), where x is the number of edges. The actual meaning is that the more complex the relationship network information is, the less suspicious it is. The purpose is to extract these less suspicious company nodes; generally, these companies are listed companies with high reputations. At the same time, those company nodes with a high degree of suspicion and few edges connected to the nodes are excluded, which are not conducive to predicting the stock price, which is the so-called noise.After the initial suspicious degree is determined, in the model iteration process, Fraudar greedily removes all nodes with the lowest suspicious degree step by step. However, each iteration traverses all nodes to locate the minimum value, which is very expensive. For this purpose, a priority tree is constructed as shown in Figure2, and the parent node records the minimum value of its child nodes, so as to start from the global minimum value recorded by the root node, and you can quickly locate the leaf node corresponding to the minimum value and then delete it. At the same time, the suspicious network degree and priority tree are updated, and the global average questionable degree G(∗) of the remaining nodes increases gradually. When all node iterations have been removed, backtrack this process until G(∗) reaches the maximum iteration. The corresponding retained node is the target node, and the relationship network between them is the high-density subgraph of the entire network.Figure 2
Priority tree.


## 2.4. Relational Modeling Module

If node JV appears in the neighbor window of node vi in a randomly generated walk route on G with a specified window size k, they are neighbor nodes as long as node vi reaches VJ within k steps. Numerous pathways are generated from the graph using a truncated random walk. Each neighboring node is produced in this manner, and information between adjacent nodes is shared utilizing the graph neural network’s primary function. The data from neighboring nodes are aggregated and added to the representation of each node, effectively merging information from various node and connection types. Each layer of the structured network is meant to convey the significance of neighboring nodes and relation kinds. The final node representation combines the learned vector with its node characteristics and acts as a graph representation for the learned input vector. The graph representation algorithm is as follows:Algorithm 1: Node relationship modeling algorithm.
Input: graph G (V, E) node feature vector fi, random walk length a1, slidingOutput: the size of the moving window (a2), the number of times each node travels (a3), the node represents the vector dimension (d), batch size (b), and gradient update step c;(1)
Randomly initialize the node representation vector w(2)
D ⟵ (G,a1,a3) a2(3)
While does not converge do(4)
Batches⟵ConstgructBatch (D,b)(5)
For each batch B in Batches do:(6)
∇w=0(7)
for each sample (vi, vj,λ) in B do(8)
∇ wi ⟵ ∇ wi + ∂L∂wi(9)
End for(10)
W⟵w−c∇w=0(11)
End for(12)
End while


## 2.5. Specific Task Module

After updating the node representation using relational modeling, the node representation will be fed back to a specific task module. Node representations can be used in different tasks with appropriate models. This study conducts experiments on a graph-based learning task: individual stock prediction.FHAN: comparing companyi in the feature extraction module at time the f-dimensional feature vector is denoted as eti ∈ Rf. Edges can be defined between different types of relationships. The target node i and the set of adjacent nodes need to be known from each relation type for neural graph networks. Put the neighbor i in relation type demoted as Nirm, while denoting the embedding vector of relational m as erm ∈ Rd. d is the dimension of the relational embedding vector. Hopefully, the model will filter out some of the noise, as companies have many different types of relationships, and some information is irrelevant to forecasting stock price movements.


## 2.6. Attention Mechanism Layer

Attention processes are frequently utilised to assign a weight to particular pieces of information. Our stock prediction hierarchical attention network (FHAN) chooses only important information at each level using a hierarchically built attention mechanism. As seen in Figure3, FHAN picks critical information of the same relationship type from neighboring nodes in the first layer. The attention mechanism is utilised to determine the current weight differences between adjacent nodes. To calculate these attention scores, the relational embedding vector erm and node representations i and j are concatenated into a vector, denoted as Xijrm∈R2f+d; the attention score is calculated as follows:(1)Vij=XijrmWs+bs,aijrm=expVij∑​expVik,k€Nirm,where Ws and bs are learnable parameters used to compute the attention score, this formula is used to calculate the attention weight value, and all weighted node representations are combined to calculate the company’s relationship vector representation m. Selectively information is gathered from specific relationships of neighboring nodes. The vector srmi contains the primary information from the relation vector m. The representation of industry relationships summarizes the overall industry status of the target company, and our model should prioritize transaction decisions based on aggregated information for each connection. The second layer of FHAN uses another attention mechanism to assign weights to information continuously. The vector srmi containing the primary information representing the situation of the current company ei, is input to the relevant attention layer with the relational embedding vector erm with xirm∈R2f+d.(2)Virm=XirmWr+br,airm=expVirm∑expVirk.Figure 3
Accuracy of training dataset on different models.


## 2.7. Stock Forecast Layer

Classify stock price movements by two types of labels: up and down. For the individual stock preselection task, a linear transformation layer is added:(3)Yi=softmaxeiWpn+bpn.Among them,Wpn∈Rd×l,bpn∈Rl; this paper uses the cross-entropy loss to train the company-related data model.(4)Lossnode=∑i∈Zu∑c=1lYiclnYic.


## 3. Experimental Setup and Result Analysis

### 3.1. Experimental Environment and Dataset

All experiments in this paper are implemented based on the Tensor flow platform library, using the CPU Intel I7 processor, and the GPU is NVIDIA RTX1080Processor, RAM 16 GB, and OS is Ubuntu.This article takes the S&P 500 constituent stocks as the research object and crawls the data set of the stock prices of these target companies in the past six years from Yahoo Finance, from 2013/05/21 to 2019/05/20. This paper uses the stock price logarithmic rate of return Rti = ln pti − ln pt − 1i commonly used in the financial industry as the original feature input to the feature extraction module. The company’s historical stock price logarithmic rate of return is the time series [Rt − li, Rt − l + 1i ,…, Rt − 1i]. Collect the related data of US stock companies from Wiki database. If there is a relationship between corporate entities, it can be regarded as an edge, and a single corporate entity is a node. Wiki database can be viewed as a hierarchical graph with a large number of edges and nodes. Some companies are not very closely related. Using the meta-path method widely used in hierarchical graphs to connect these company nodes, after removing unrelated companies, there are 430 remaining companies, and it is found that there are 71 major relationships among these companies relation. The purpose of this study is to explore whether the correlation data among these target companies play a significant role in stock price prediction.


### 3.2. Evaluation Metrics

Stock price change prediction is a classification task that separately predicts each period’s stock price. Here, two indicators, accuracy rate (Acc) and F1 value, are used to evaluate the prediction model’s performance, and the scores are finally averaged. Table1 is divided into four types according to the FHAN prediction category combination: true case (TP), false positive (FP), true negative (TN), and false-negative (FN), calculated as follows:(5)Acc=TP+TNTP+TN+FP+FN.Table 1
Evaluation index.
The true situationForecast resultPositive example (rising)Negative (fall)Positive example (rising)TP (predicted rise, actual rise)FN (forecast fall, actual rise)Negative (fall)FP (forecast up, actual down)TN (forecast drop, actual drop)(6)P=TPTP+FP,R=TPTP+FN,F1=2PRP+R.


### 3.3. Experimental Results and Analysis

To verify the performance of the FHAN model, four baseline models, MLP, CNN, LSTM, and GCN, and the LSTM-attention model are compared with FHAN. After many experiments, the model parameters are set and Table2 obtains the F1 scores of the top five types of relational companies according to the graph relationship information. It can be seen that the stock prices of large companies with open and transparent relationship information can be more accurately measured.Table 2
F1 score of relation.
Relationship typeF1Parent company0.3359Government investment0.3344Fund company investment0.3191Trust investment0.3097To ensure the accuracy and objectivity of the experimental data, each model was run ten times on the same training set and test set, respectively. The accuracy and F1 value were obtained as the final results of the model, as shown in Table3. It can be seen from Table 3 that, due to the integration of the Fraudar algorithm, FHAN embeds graph structure and node feature information, as well as multilayer attention modules. Compared with other models, the accuracy rate increases by about 4%, and the highest increase is about 24%. However, compared with the more popular LSTM-attention model, the accuracy and F1 score are slightly improved on the test set shown in Figure 4. Figure 5 shows the F1 score of different training datasets of different models. The main reason is that the attention mechanism modules of the two are shared and play an essential role in enhancing the model effect. Although the Fraudar algorithm is embedded in this paper, the stability is not high enough due to the inability to eliminate noise interference.Table 3
Comparative experiment.
Model typeTraining datasetTest setAccuracyF1AccuracyF1CNN0.35410.32050.34080.3122LSTM0.35810.32240.34870.3208GCN0.29510.27830.28090.2783MLP0.29660.26810.28630.2653LSTM-attention0.35960.32890.35530.3277FHAN0.36250.33150.35530.3311Figure 4
F1 score of relation.Figure 5
F1 of training dataset on different models.


### 3.4. Analysis of Transaction Backtest Results

The initial capital set by the experiment is 1 million yuan. From the backtest results, Figure6 shows that, with the black line S&P 500 index as the benchmark, the FHAN, CNN, and LSTM-attention strategies are significantly higher than this level, and the excess return alpha is values which are all above 20%. The FHAN strategy is more elevated than CNN and LSTM-attention in annualized rate of return and better than other strategies in significant indicators such as Sharpe ratio, indicating that in highly correlated stock data, the FHAN model is better than other deep neural networks represented in Figure 7. Therefore, the network model works better.Figure 6
Accuracy of test dataset on different models.Figure 7
F1 of test dataset on different models.


## 3.1. Experimental Environment and Dataset

All experiments in this paper are implemented based on the Tensor flow platform library, using the CPU Intel I7 processor, and the GPU is NVIDIA RTX1080Processor, RAM 16 GB, and OS is Ubuntu.This article takes the S&P 500 constituent stocks as the research object and crawls the data set of the stock prices of these target companies in the past six years from Yahoo Finance, from 2013/05/21 to 2019/05/20. This paper uses the stock price logarithmic rate of return Rti = ln pti − ln pt − 1i commonly used in the financial industry as the original feature input to the feature extraction module. The company’s historical stock price logarithmic rate of return is the time series [Rt − li, Rt − l + 1i ,…, Rt − 1i]. Collect the related data of US stock companies from Wiki database. If there is a relationship between corporate entities, it can be regarded as an edge, and a single corporate entity is a node. Wiki database can be viewed as a hierarchical graph with a large number of edges and nodes. Some companies are not very closely related. Using the meta-path method widely used in hierarchical graphs to connect these company nodes, after removing unrelated companies, there are 430 remaining companies, and it is found that there are 71 major relationships among these companies relation. The purpose of this study is to explore whether the correlation data among these target companies play a significant role in stock price prediction.


## 3.2. Evaluation Metrics

Stock price change prediction is a classification task that separately predicts each period’s stock price. Here, two indicators, accuracy rate (Acc) and F1 value, are used to evaluate the prediction model’s performance, and the scores are finally averaged. Table1 is divided into four types according to the FHAN prediction category combination: true case (TP), false positive (FP), true negative (TN), and false-negative (FN), calculated as follows:(5)Acc=TP+TNTP+TN+FP+FN.Table 1
Evaluation index.
The true situationForecast resultPositive example (rising)Negative (fall)Positive example (rising)TP (predicted rise, actual rise)FN (forecast fall, actual rise)Negative (fall)FP (forecast up, actual down)TN (forecast drop, actual drop)(6)P=TPTP+FP,R=TPTP+FN,F1=2PRP+R.


## 3.3. Experimental Results and Analysis

To verify the performance of the FHAN model, four baseline models, MLP, CNN, LSTM, and GCN, and the LSTM-attention model are compared with FHAN. After many experiments, the model parameters are set and Table2 obtains the F1 scores of the top five types of relational companies according to the graph relationship information. It can be seen that the stock prices of large companies with open and transparent relationship information can be more accurately measured.Table 2
F1 score of relation.
Relationship typeF1Parent company0.3359Government investment0.3344Fund company investment0.3191Trust investment0.3097To ensure the accuracy and objectivity of the experimental data, each model was run ten times on the same training set and test set, respectively. The accuracy and F1 value were obtained as the final results of the model, as shown in Table3. It can be seen from Table 3 that, due to the integration of the Fraudar algorithm, FHAN embeds graph structure and node feature information, as well as multilayer attention modules. Compared with other models, the accuracy rate increases by about 4%, and the highest increase is about 24%. However, compared with the more popular LSTM-attention model, the accuracy and F1 score are slightly improved on the test set shown in Figure 4. Figure 5 shows the F1 score of different training datasets of different models. The main reason is that the attention mechanism modules of the two are shared and play an essential role in enhancing the model effect. Although the Fraudar algorithm is embedded in this paper, the stability is not high enough due to the inability to eliminate noise interference.Table 3
Comparative experiment.
Model typeTraining datasetTest setAccuracyF1AccuracyF1CNN0.35410.32050.34080.3122LSTM0.35810.32240.34870.3208GCN0.29510.27830.28090.2783MLP0.29660.26810.28630.2653LSTM-attention0.35960.32890.35530.3277FHAN0.36250.33150.35530.3311Figure 4
F1 score of relation.Figure 5
F1 of training dataset on different models.


## 3.4. Analysis of Transaction Backtest Results

The initial capital set by the experiment is 1 million yuan. From the backtest results, Figure6 shows that, with the black line S&P 500 index as the benchmark, the FHAN, CNN, and LSTM-attention strategies are significantly higher than this level, and the excess return alpha is values which are all above 20%. The FHAN strategy is more elevated than CNN and LSTM-attention in annualized rate of return and better than other strategies in significant indicators such as Sharpe ratio, indicating that in highly correlated stock data, the FHAN model is better than other deep neural networks represented in Figure 7. Therefore, the network model works better.Figure 6
Accuracy of test dataset on different models.Figure 7
F1 of test dataset on different models.


## 4. Conclusion

The advantages of the FHAN model are as follows; due to the combination of the Fraudar algorithm, it can process multitype node and relationship information in the network, data can be transferred from one node to another through different relationships, and various types of nodes can be integrated by using FHAN, mutual promotion, and upgrading. The calculation of the attention score can be performed in parallel based on nodes and meta-paths, and the total complexity is linearly related to the number of nodes and the number of nodes based on meta-paths. Attention modules are shared, and the number of parameters does not depend on the scale of the hierarchy. The model has better interpretability for learning nodes. Based on the attention score, it is possible to see which nodes or meta-paths contributed to help analyze and interpret experimental results.The Fraudar module has the same shortcomings as other unsupervised algorithms such as clustering in terms of model validity. The stability is poor, and it needs to be combined with statistical indicators to make secondary judgments. However, expert review requires a lot of manual intervention and cannot be generalized. For example, when some critical information is captured from the relational network, some irrelevant information is also extracted. Of course, to enhance the credibility of the model output, the graph can be pre-pruned first, which can effectively reduce the amount of data computation and time. For example, in this paper, all companies with irrelevant information network nodes are eliminated, and only those with related information are retained.Given the shortcomings of the current graph relational data network method in stock price forecasting, this paper proposes an improved multilayer graph attention network model combined with the Fraudar algorithm for the first time. The model is significantly better than other neural network models in individual stock prediction, and the experimental results also prove the importance of relational data in stock price prediction. However, the model still has a lot of room for improvement. This paper studies the classification model based on the data of the entire listed company, which is not targeted enough. The analysis of specific industries is the future research direction. This article only uses a single database for research. In the future, interested readers can integrate news text information and various databases into the relational network. At the same time, they can also try to conduct in-depth research on China’s stock market and market index, which can be used as a reference for in-depth analysis of Saudi Arabia’s financial industry.



---

*Source: 5200110-2022-05-20.xml*