# STGAT: Spatial-Temporal Graph Attention Neural Network for Stock Prediction
## 4 Experiments
### Experimental Results
#### 4.3.1 Predictive Performance of STGAT
\begin{table}
\begin{tabular}{l l l} \hline \hline
**Indicators** & **Formula** & **Meaning** \\ \hline MAE & \(\dfrac{1}{n}\sum\limits_{i=1}^{n}|y_{i}-\hat{y}_{i}|\) & Average of absolute errors between predicted and actual values \\ DA & \(\dfrac{1}{n}\sum\limits_{i=1}^{n}\begin{cases}1&\text{if }\Delta y_{i} \cdot\Delta\hat{y}_{i}>0\\ 0&\text{otherwise}\end{cases}\) & Proportion of correct directional predictions where \(\Delta y_{i}=y_{i}-y_{i-1}\) and \(\Delta\hat{y}_{i}=\hat{y}_{i}-y_{i-1}\) \\ RE & \(\dfrac{|y_{i}-\hat{y}_{i}|}{|y_{i}|}\) & Ratio of absolute error to the actual value \\ RMSE & \(\sqrt{\dfrac{1}{n}\sum\limits_{i=1}^{n}(y_{i}-\hat{y}_{i})^{2}}\) & Square root of MSE, in the same units as the target variable \\ R\({}^{2}\) & \(1-\dfrac{\sum\limits_{i=1}^{n}(y_{i}-\hat{y}_{i})^{2}}{\sum\limits_{i=1}^{n}(y_ {i}-\hat{y})^{2}}\) & Proportion of variance explained by the model \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Indicators of prediction results. dynamics present in the stock price movements. On the other hand, time series models, like the GRU and RNN, benefit from this setup as they are inherently designed to learn and predict based on temporal dependencies, leading to a notable increase in prediction accuracy. STGAT, with its ability to integrate both temporal features and graph-based relationships, demonstrates significant advantages in this scenario. By combining temporal and spatial features, STGAT can identify and utilize the fusion of evolving stock price trends and entity interactions, showcasing its capability to handle the complexity and randomness of stock market data more effectively than models focused on a single aspect. Tables 5 and 6 show the performance of the models in the US stock market based on the two dataset-partitioning methods mentioned above. Because the US stock market follows the T+0 trading rule and we selected 462 stocks from the S&P 500 index, the stock volatility and dataset complexity in the US market are much more remarkable than in the A-share market. The T+0 trading rule allows for rapid intraday trading, which intensifies short-term price fluctuations as investors execute high-frequency and speculative strategies, leading to heightened volatility. Additionally, the inclusion of 462 S&P 500 stocks forms a large and highly interconnected graph network, increasing the learning difficulty for models as they must capture both intricate temporal patterns and complex stock relationships. These combined factors amplify the challenges in prediction, leading to an overall increase in error indicators when models are applied to the US stock market. In Table 5, even though the prediction capability of all models declines due to the increased volatility and complexity of the US stock market, STGAT consistently demonstrates the highest robustness and adaptability. Despite the overall performance drop in key metrics, STGAT remains the best-performing model with the lowest errors and the highest \(R^{2}\) and accuracy values. This indicates that the integration of spatiotemporal features enables STGAT to perform better in prediction with higher robustness and adaptability, which are crucial in handling more volatile and complex datasets. From Table 6, it is evident \begin{table}
\begin{tabular}{l c c c c c c} \hline \hline
**Model** & **MAE** & **DA** & **RE** & **RMSE** & **R2** & **Accuracy** \\ \hline GCN & 2.9273 & 54.20\% & 0.2405 & 4.9487 & 0.7544 & 0.5760 \\ GRU & 0.8597 & 61.71\% & **0.0659** & 1.4769 & 0.9796 & 0.7367 \\ LSTM & 1.0651 & 59.62\% & 0.0791 & 1.9539 & 0.9643 & 0.7146 \\ MLP & 1.1231 & 56.11\% & 0.0878 & 1.8872 & 0.9643 & 0.7143 \\ RNN & 0.8785 & **62.80\%** & 0.0679 & 1.5475 & 0.9776 & 0.7331 \\ TCN & 0.8820 & 60.62\% & 0.0727 & 1.4076 & 0.9801 & 0.7075 \\ Transformer & 1.7136 & 57.20\% & 0.1338 & 2.8327 & 0.9195 & 0.6233 \\ STGAT & **0.8440** & 62.77\% & 0.0682 & **1.3349** & **0.9821** & **0.7443** \\ \hline \hline \end{tabular}
\end{table}