# Reinforcement Learning with Self-Attention Networks for Cryptocurrency Trading
## Appendix A Exchange Fee Minimization Algorithms
### The Solution for the General Case
\[f(\rho)\stackrel{{\text{\tiny{\textdef}}}}{{=}}\frac{1-\sum_{i> 0}\left[\left(g_{i0}+f_{0i}\right)\left(\widehat{w}^{k}_{i}-\rho w^{k+1}_{i} \right)^{+}-f_{0i}\widehat{w}^{k}_{i}\right]}{1+\sum_{i>0}f_{0i}w^{k+1}_{i}}\] (A18)  
**Lemma A2**. : _The function \(f(\rho)\) (see Equation (A18)) increases monotonically, i.e., \(\rho_{1}>\rho_{1}\Rightarrow f(\rho_{1})\geq f(\rho_{2})\). Furthermore, \(f(\rho)\) is a concave function._  
Proof. : Note, the expression \(\left(\widehat{w}^{k}_{i}-\rho w^{k+1}_{i}\right)^{+}\) on the RHS of Equation (A18) is a convex, monotonically decreasing function of \(\rho\) for all \(i\). Then, the expression  
\(\sum_{i>0}\left(g_{i0}+f_{0i}\right)\left(\widehat{w}^{k}_{i}-\rho w^{k+1}_{i }\right)^{+}\) is also convex and monotonically decreasing since it is just a weighted summation of convex, monotonically decreasing functions with positive scaling weights \(\big{(}g_{i_{0}}+f_{0i}\big{)}\). However, the summation has a negative sign at the front, changing the expression into a concave, monotonically increasing function instead. The rest of elements on the RHS of Equation (A18) are simply constants that translate the expression on the plane formed by \(\rho\) and \(f(\rho)\), but do not change its concave and monotonically increasing nature. \(f(0)>0\). Proof. : Substituting 0 for \(\rho\) in Equation (A18) results in Equation (A19). \[ \begin{split} f(0)&=\frac{1-\sum_{i>0}\Bigl{[}(g_{i 0}+f_{0i})\bar{w}_{i}^{k}-f_{0i}\bar{w}_{i}^{k}\Bigr{]}}{1+\sum_{i>0}f_{0i}w_{i} ^{k+1}}\\ &=\frac{1-\sum_{i>0}g_{i0}\bar{w}_{i}^{k}}{1+\sum_{i>0}f_{0i}w_{i} ^{k+1}}\end{split} \] (A19)  
Note, Equation (A19) implies \(f(0)\) cannot be negative or zero because both numerator and denominator are always positive. It is obvious that the denominator is positive since each part of the expression is positive. The numerator, on the other hand has negative expressions; therefore, it has to be analyzed carefully. Note, The definition of \(g_{i0}\) (see Equation (A5)) implies \(g_{i0}<1\) for all \(i\) and \(\sum_{i}\bar{w}_{i}^{k}=1\); thus, \(\sum_{i}g_{i0}\bar{w}_{i}^{k}<1\), which implies the numerator is positive. \(f(1)\leq 1\). Proof. : This fact is proven by contradiction as follows. Assume \(f(1)>1\). Then, substituting 1 for \(\rho\) in Equation (A18) gives Equation (A20). \[ \begin{split} f(1)&=\frac{1-\sum_{i>0}\Bigl{[} \big{(}g_{i_{0}}+f_{0i}\big{)}\Big{(}\bar{w}_{i}^{k}-w_{i}^{k+1}\Big{)}^{+}-f_{ 0i}\bar{w}_{i}^{k}\Bigr{]}}{1+\sum_{i>0}f_{0i}w_{i}^{k+1}}>1\\ &\Rightarrow-\sum_{i>0}\Bigl{[}\big{(}g_{i_{0}}+f_{0i}\big{)} \Big{(}\bar{w}_{i}^{k}-w_{i}^{k+1}\Big{)}^{+}-f_{0i}\bar{w}_{i}^{k}\Bigr{]}> \sum_{i>0}f_{0i}w_{i}^{k+1}\end{split} \] (A20)  
Then, using Equation (A6) in Equation (A20) gives Equation (A21). \[ \begin{split}&-\sum_{i>0}\Bigl{[}\big{(}g_{i_{0}}+f_{0i}\big{)} \Bigl{[}\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k}\Big{)}^{+}+\Big{(}\bar{w}_{i}^{k}-w _{i}^{k+1}\Big{)}\Bigr{]}-f_{0i}\bar{w}_{i}^{k}\Bigr{]}>\sum_{i>0}f_{0i}w_{i}^{ k+1}\\ &\Rightarrow-\sum_{i>0}\Bigl{[}\big{(}g_{i_{0}}+f_{0i}\big{)} \Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k}\Big{)}^{+}+g_{i_{0}}\Big{(}\bar{w}_{i}^{k}- w_{i}^{k+1}\Big{)}\Bigr{]}>0\\ &\Rightarrow\sum_{i>0}g_{i_{0}}\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k} \Big{)}>\sum_{i>0}(g_{i_{0}}+f_{0i})\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k}\Big{)}^{+ }\\ &\Rightarrow\sum_{i>0}g_{i_{0}}\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k} \Big{)}>\sum_{i>0}g_{i0}\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k}\Big{)}^{+}\end{split} \] (A21)  
And Equation (A21) is clearly a contradiction since \(\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k}\Big{)}\leq\Big{(}w_{i}^{k+1}-\bar{w}_{i}^{k }\Big{)}^{+}\) for any asset \(i\). The function \(f(\rho)\) defined in Equation (A18) cannot have more than one fixed-point (\(f(\rho)=\rho\)) in the interval \([0,1]\). **Proof. ** This fact is proven by contradiction as follows. Assume \(f(\rho)\) has at least two different fixed-points in the interval \([0,1]\), namely \(\rho_{1}\) and \(\rho_{2}\). Assume WLOG \(\rho_{1}<\rho_{2}\). Then, using the definition of fixed-point, we can write Equation (A22).