# Smart Robotic Strategies and Advice for Stock Trading Using Deep Transformer Reinforcement Learning
## 3 Methodology and Proposed Model
### Data
#### 3.2.3 Data Stationarity
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Index/Stocks** & **ADF Statistic** & \(p\)**-Value** & \multicolumn{2}{c}{**Critical Values**} & \multicolumn{1}{c}{**Decision**} \\ \hline Telecommunication & \(-\) 1.161312 & 0.690013 & 1\%: \(-\)3.435 \%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Savid Telecom & \(-\)1.594104 & 0.486555 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Company (7010) & 1.187172 & 0.995896 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Banks Index (TRNI) & 1.187172 & 0.995896 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Al Rajhi Banking and & & & & \\ Investment & 2.972744 & 1.000000 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Corp(1120) & & & & \\ Materials Index & \(-\)0.562991 & 0.879127 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ TMI & & & & \\ Saudi Basic & & & & \\ Industries & \(-\)1.878952 & 0.342027 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Corporation (2010) & & & & \\ Utilities Index (TUTI) & 0.334678 & 0.978881 & 1\%: \(-\)3.435 5\%: \(-\)2.864 10\%: \(-\)2.568 & Failed to Reject H\({}_{\alpha}\), Time-Series is Non-Stationary \\ Saudi Electricity & & & & \\ Company (5110) & & & & \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Results of Augmented Dickey–Fuller (ADF) Unit Root Test. Figure 9: Decomposition of 7010 Stock Data: Trend, Seasonal (Periodic), and Residual Components. Table 2 makes it quite clear that the null hypothesis was not rejected for the data of indices and stocks, confirming that our data were not stationary. This can be observed by the fact that the absolute value of the ADF-statistic was less that the absolute value of the ADF-critic at the 1% level (3.592462), as well as by the fact that the \(p\)-values were higher than 0.05. Data that are non-stationary can be handled using various techniques, including differencing and transformation. The purpose of a difference is to eliminate variance in the mean, where subtracting the current observation \((x_{t})\) from the prior observation \((x_{t-1})\) yields the difference. The mathematical expression for differencing is as follows:  
\[x_{t}=x_{t}-x_{t-1}. \tag{5}\]  
Transformations, however, are used to stabilize non-constant variances by applying some mathematical function to each time-series value to remove a pattern. The most common transformation methods are log transforms, square roots, and power transforms, including the Box-Cox transformation and the Yeo-Johnson transformation. In this study,  
Figure 10: Decomposition of 5110 Stock Data: Trend, Seasonal (Periodic), and Residual Components. we employ Yeo-Johnson transformations. Mathematically speaking, the Yeo-Johnson transformation may be expressed as:  
\[y_{i}^{(\lambda)}= \begin{cases}\left((y_{i}+1)^{\lambda}-1\right)/\lambda&\text {if }\lambda\
eq 0,y\geq 0\\ \log(y_{i}+1)&\text{if }\lambda=0,y\geq 0\\ -\left[(-y_{i}+1)^{(2-\lambda)}-1\right]/(2-\lambda)&\text{if }\lambda\
eq 2,y<0\\ -\log(-y_{i}+1)&\text{if }\lambda=2,y<0,\end{cases}  \tag{6}\]  
where \(y_{i}\) denotes the observed feature transformed using a parameter \(\lambda\). Maximum likelihood is typically used to estimate \(\lambda\) in the Yeo-Johnson transformation, assuming that the transformed variable follows a normal distribution [50]. Nonetheless, according to [51], the application of a transform on its own does not necessarily cause the data to become stationary. This conclusion was reached using the ADF test. Therefore, to make data stationary, differencing was also applied in combination with the transform.