# Reinforcement Learning with Self-Attention Networks for Cryptocurrency Trading
## Appendix A Exchange Fee Minimization Algorithms
### The Solution for the General Case
And using the fact that \(f(\rho)\) is concave and the definition of concave function, which can be found in the work of [PERSON] and [PERSON] (2016), we can write Equation (A23), where \(x_{1}\) and \(x_{2}\) are any elements in the domain of the function and \(\theta\) is any value in the interval \([0,1]\). \[f(\rho_{1})=\rho_{1},\quad f(\rho_{2})=\rho_{2}\] (A22)  
\[f(\theta x_{1}+(1-\theta)x_{2})\geq\theta f(x_{1})+(1-\theta)f(x_{2}),0\leq \theta\leq 1\] (A23)  
Next, substituting \(x_{1}\) and \(x_{2}\) by \(0\) and \(\rho_{2}\), respectively in Equation (A23) results in Equation (A24). \[f(\theta 0+(1-\theta)\rho_{2})\geq\theta f(0)+(1-\theta)f(\rho_{2})\] (A24)  
Note, since \(\rho_{1}<\rho_{2}\), we can define \(\widehat{\theta}\) as the solution of equation \(\rho_{1}=\widehat{\theta}0+(1-\widehat{\theta})\rho_{2}\), which always gives a value in the interval \([0,1)\). Then, substituting this expression in Equation (A22) for \(\rho_{1}\) gives Equation (A25). \[f(\widehat{\theta}0+(1-\widehat{\theta})\rho_{2})=\widehat{\theta}0+(1- \widehat{\theta})\rho_{2}\] (A25)  
And substituting Equation (A22) for \(\rho_{2}\) in Equation (A25) gives Equation (A26). \[f(\widehat{\theta}0+(1-\widehat{\theta})\rho_{2})=\widehat{\theta}0+(1- \widehat{\theta})f(\rho_{2})\] (A26)  
Finally, substituting zero for \(f(0)\) in Equation (A26) by Equation (A3) results in the inequality shown in Equation (A27). \[f(\widehat{\theta}0+(1-\widehat{\theta})\rho_{2})<\widehat{\theta}f(0)+(1- \widehat{\theta})f(\rho_{2})\] (A27)  
But, Equation (A27) contradicts Equation (A24). Therefore, the assumption that \(f(\rho)\) has more than one fixed-point is false. \(\square\)  
Note, we have not proved that there exists a fixed-point for \(f\) in the interval \([0,1]\), but only proved there cannot be more than one. In fact, there is always a single fixed-point for \(f\) in that interval as proven in Lemma A6. **Lemma A6**. : _The sequences \(\{\rho_{k}\}_{0}^{\infty}\), where \(\rho_{0}\in[0,1]\) and \(\rho_{k}=f(\rho_{k-1})\) for \(k>0\), with \(f(\rho)\) defined by Equation (A18), monotonically converge to the only fixed-point of \(f\) in the interval \([0,1]\)._  
**Proof. ** If the first element of the sequence \(\rho_{0}\) is chosen to be in the interval \([0,1]\), then by Lemmas A2 to A4, the next element of the sequence \(x_{1}\) falls in the interval \((0,1]\). These lemmas impose hard limits for \(f\) in the interval \([0,1]\), namely \(0<f(0)\leq f(\rho)\leq f(1)\leq 1\). Using this fact we prove the monotonicity of the sequence by induction. Assume that \(\rho_{k}\geq\rho_{k-1}\). Then by Lemma A2 we obtain Equation (A28). \[ \begin{split}&\rho_{k}\geq\rho_{k-1}\\ &\Rightarrow f(\rho_{k})\geq f(\rho_{k-1})\end{split} \] (A28)  
And applying the definition of the sequence to Equation (A28) results in Equation (A29). \[ \begin{split}&\rho_{k+1}=f(\rho_{k})\geq f(\rho_{k-1})=\rho_{k} \\ &\Rightarrow\rho_{k+1}\geq\rho_{k}\end{split} \] (A29)  
Therefore, if \(\rho_{1}\geq\rho_{0}\), the whole sequence is monotonically increasing. Following a similar argument, we can also show if \(\rho_{1}\leq\rho_{0}\), the sequence decreases monotonically. Then, the base step of the induction is determined by the outcome of \(f(\rho_{0})\). Therefore, since the sequence is monotonic and bounded above and below, the Monotone ConvergenceTheorem [33] implies all sequences defined in Lemma A6 must converge. This fact is summarized in Equation (A30) for any \(\rho_{0}\) in the interval \([0,1]\). \[ \begin{split}&\lim_{k\to\infty}\rho_{k+1}=\rho_{k}\\ &\Rightarrow f(\rho_{k})=\rho_{k}\text{ as }k\to\infty\end{split} \] (A30)  
Finally, using Lemma A5 we conclude that all sequences defined in Lemma A6 can only converge to a unique value. The solution returned by Algorithm 2 is optimal. Lemma A1 gives a necessary (but not sufficient) condition for any optimal solution, namely the solution has to satisfy the constraints given in Equation (A3). Additionally, if there is an optimal solution, it has to be a fixed-point of Equation (A18).