## 3 Data and Method
### Proposed Method
#### 3.2.3 Long-Distance Loss  
In deep learning models, the loss function plays a pivotal role, serving as an optimization target and influencing the learning process of the model. For time series prediction tasks, such as stock price forecasting, capturing long-term trends and dependencies is crucial. However, the loss function utilized in standard Transformer models, such as Mean Squared Error (MSE), predominantly focuses on the prediction error at each time point and might not adequately capture long-term trend information. To address this challenge, this study introduces a novel loss function termed \"Long-Distance Loss\". This loss function not only considers the prediction error at each time point but also integrates long-term trend information, thereby effectively capturing long-term dependencies in time series data. Specifically, assuming the model's predicted value at time point \(t\) is \(\hat{y}_{t}\) and the actual value is \(y_{t}\), the loss based on MSE is computed as:  
\[L_{\text{MSE}}(t)=(\hat{y}_{t}-y_{t})^{2} \tag{20}\]  
In the Long-Distance Loss, an error term associated with long-term trends is further incorporated. To compute this error term, a time window \(w\) is first defined. Then, for each time point \(t\), the discrepancies between predicted and actual values from \(t-w\) to \(t\) are considered to compute their cumulative error:  
\[E_{t}=\sum_{i=t-w}^{t}(\hat{y}_{i}-y_{i}) \tag{21}\]  
Based on the aforementioned cumulative error \(E_{t}\), the loss for the long-term trend is defined as:  
\[L_{\text{LD}}(t)=\lambda\times E_{t}^{2} \tag{22}\]Here, \(\lambda\) is a hyperparameter for balancing the MSE loss and long-term trend loss. Consequently, the final Long-Distance Loss is defined as:  
\[L(t)=L_{\text{MSE}}(t)+L_{\text{LD}}(t) \tag{23}\]  
Such design holds profound mathematical and practical significance. Mathematically, by incorporating the long-term trend loss, the model is encouraged to focus not just on individual time point predictions but also on overall trends. This aids the model in better capturing long-term dependencies in the data, subsequently enhancing prediction accuracy. Practically, stock market prices often reflect long-term trends. For instance, a significant economic event might influence the stock market for several months or even years. Employing Long-Distance Loss allows the model to more effectively capture these long-lasting impacts, leading to more accurate predictions. Compared to the original loss function of the Transformer, Long-Distance Loss offers distinct advantages. Firstly, it amalgamates both short-term and long-term error information, presenting the model with a more comprehensive optimization objective. Secondly, by introducing the long-term trend loss, the model tends to place greater emphasis on long-term data dependencies during training, enhancing prediction accuracy. Lastly, this loss function also affords greater training stability for the model, as it reduces sensitivity to short-term noise. In summary, Long-Distance Loss, by combining short-term and long-term error information, offers the model a more comprehensive and stable optimization target, resulting in improved prediction accuracy in stock price forecasting tasks.