# STGAT: Spatial-Temporal Graph Attention Neural Network for Stock Prediction
## 3 System Framework
### Asset Correlation  
In the dynamic and volatile stock market, each stock exhibits unique fluctuations influenced factors such as macroeconomic conditions, industry trends, and company fundamentals. The most intuitive way to reveal the dynamic changes in overall market performance is using the stock's relation graph. The returns of various assets in the stock market are intricately interrelated, forming a complex and highly refined dependency structure. Treating stocks as individual nodes and evaluating the relationships between stocks as edges using specific metrics allows us to intuitively capture the complex interdependencies between stocks and leverage a graph attention network to deeply explore hidden spatial-temporal features in the data, thereby achieving accurate analysis and prediction of market dynamics. Therefore, we chose Pearson's Coefficient (PCC) as the metric to measure the correlation between stocks:  
\[r_{xy}=\frac{\sum_{i=1}^{n}(x_{i}-\bar{x})(y_{i}-\bar{y})}{\sqrt{\sum_{i=1}^{n} (x_{i}-\bar{x})^{2}}\sqrt{\sum_{i=1}^{n}(y_{i}-\bar{y})^{2}}}, \tag{8}\]  
where \(r_{xy}\) is the PCC between stocks \(x\) and \(y\), \(\bar{x}\) and \(\bar{y}\) mean the average prices of stocks \(x\) and \(y\). PCC measures the strength and direction of the linear relationship between two stocks' price movements, which ranges between \(-1\) and \(1\). To construct graph structures suitable for deployment in a graph attention network, non-negative weights are typically required. To address this, the original correlation coefficients are scaled using the Sigmoid function, mapping them into the interval \([0,1]\). Shown as heatmaps in Figure 2, the closer the value of \(r_{xy}\) is to \(1\), the stronger the correlation between the two stocks; conversely, the closer it is to \(0\), the weaker the correlation.  
Based on the scaled value of the correlation coefficient, this article analyzes the correlation matrix of the stock market and categorizes the correlations between stocks into strong and weak relations. A threshold value, denoted as \(\alpha=0.4\), is applied to differentiate these relations. This threshold--which aligns with the conventional classification of  
Figure 2: Partial correlation among stocks.  
Pearson's correlation coefficients in economics and social sciences, where values below 0.4 typically indicate weak associations--distinguishes weak linkages from economically meaningful interactions [51; 52], ensuring robustness against random noise inherent in efficient markets. If the scaled value of the correlation coefficient between two stocks exceeds \(\alpha\), the relationship is considered strongly correlated. Strong correlations typically indicate that stocks are influenced by shared macroeconomic factors, industry trends, or market sentiment. In contrast, when the correlation coefficient is below \(\alpha\), the stocks are deemed weakly correlated. Hence, in the graph representation, edges are added between pairs of strongly correlated stocks, and the original edge weights are set equal to their corresponding correlation coefficients. The adjacency matrix \(A^{{}^{\prime}}\) of the graph is derived from the asset correlations below:  
\[A^{{}^{\prime}}_{ij}=\frac{1}{1+e^{-A_{ij}}},\quad A_{ij}=r_{ij}\quad if\quad r _{ij}>\alpha. \tag{9}\]