# Reinforcement Learning with Self-Attention Networks for Cryptocurrency Trading
## Appendix A Exchange Fee Minimization Algorithms
### The Solution for the General Case  
The general solution for the fee minimization problem is computed using a linear program (LP). The solution is a generalization of the method presented in [22], which can solve the constrained case. The linear program is formulated using Equation (4) as the objective function and Equations (2) and (5) as constraints. However, Equation (A8) has to be modified because the objective variable (\(\rho^{k}\)) appears explicitly in the expression. Therefore, substituting \(\rho^{k}\) from Equation (4) and rearranging terms results in Equation (A8). \[ \begin{split}&(1-\sum_{k}\sum_{j}f_{kj}\tau_{kj}^{k})w_{i}^{k+1}+ \sum_{j}(1+f_{ij})\tau_{ij}^{k}-\sum_{j}\tau_{ji}^{k}=\bar{w}_{i}^{k}\\ &\text{for }i\in\{0,1,...,N-1\}\end{split} \] (A8)  
This expression allows us to formulate the search for the solution of the general case of the fee minimization problem as an LP, as shown in Equation (A9). The LP in Equation (A9) is always feasible because the LP presented in [22] for the constrained case always has a feasible solution, and is a specific case of Equation (A9). Algorithm 3 summarizes the method to find the optimal solution for the fee minimization problem using Equation (A9). However, if the number of equality constraints, inequality constraints, or variables in an LP is large, the process to solve the LP can become impractically long, which is precisely  
The new variables \(\Delta\tau^{k}_{0i}\) used in Equations (A14) and (A15) are defined in Equation (A16). This definition for the variables \(\Delta\tau^{k}_{0i}\) ensures all \(\Delta\tau^{k}_{0i}\) are proportional to their corresponding \(w^{k+1}_{i}\) and also ensures the relation \(\sum_{i}(1+f_{0i})\Delta\tau^{k}_{0i}=D\) is satisfied. Therefore, the variables \(\widehat{\tau}^{k}_{0i}\) correspond to a feasible solution to the problem since all desired weights are satisfied again. The next step is to prove the discount rate corresponding to this solution, named \(\widehat{\rho}^{k}\), is larger than \(\rho^{*k}\). \[\widehat{\tau}^{k}_{0i} \stackrel{{\text{\tiny{\textdef}}}}{{=}}\tau^{*k}_{0 i}+\Delta\tau^{k}_{0i},i\
eq\kappa\] (A14) \[\widehat{\tau}^{k}_{0k} \stackrel{{\text{\tiny{\textdef}}}}{{=}}\tau^{\prime k }_{0k}+\Delta\tau_{0k}\] (A15) \[\Delta\tau^{k}_{0i} \stackrel{{\text{\tiny{\textdef}}}}{{=}}\frac{Dw ^{k+1}_{i}}{\sum_{j}(1+f_{0j})w^{k+1}_{j}}\] (A16)  
Replacing \(\widehat{\tau}^{k}_{0k}\) from Equation (A15) for \(\tau^{\prime k}_{0k}\) in Equation (A12) results in Equation (A17), which corresponds to the equation for the asset \(\kappa\) for the constructed solution. By simplifying this expression, we arrive to a relation between \(\widehat{\rho}^{k}\) and \(\rho^{*k}\). \[\widehat{\rho}^{k}w^{k+1}_{k} =\widehat{w}^{k}_{k}-(1+f_{\kappa 0})\tau^{\prime k}_{\kappa 0}+ \widehat{\tau}^{k}_{0k}\] (A17) \[=\widehat{w}^{k}_{k}-(1+f_{\kappa 0})\tau^{\prime k}_{\kappa 0}+ \tau^{\prime k}_{0k}+\Delta\tau^{k}_{0k}\] \[=\rho^{*k}w^{k+1}_{k}+\frac{Dw^{k+1}_{\kappa}}{\sum_{j}(1+f_{0j} )w^{k+1}_{j}}\] \[=\rho^{*k}\left(1+\frac{D}{\sum_{j}(1+f_{0j})w^{k+1}_{j}}\right)w ^{k+1}_{\kappa}\] \[\Rightarrow\widehat{\rho}^{k} =\rho^{*k}\left(1+\frac{D}{\sum_{j}(1+f_{0j})w^{k+1}_{j}}\right)\]  
The fact \(w^{k}_{\kappa}>0\) was used to simplify that variable from both sides of Equation (A17). Note, Equation (A17) implies \(\widehat{\rho}^{k}>\rho^{*k}\), which contradicts Equation (A11). Therefore, the assumption that exists an optimal solution such that both \(\tau^{k}_{i0}\) and \(\tau^{k}_{0i}\) are positive for some index \(i=\kappa\) is false. This concludes the proof of Lemma A1. Let us define the function \(f(\rho)\) using the right-hand side (RHS) of Equation (A7) as shown in Equation (A18). Note, Equation (2) consist of computing \(f(\rho)\), assign that value to \(\rho\) and repeat the process over and over until \(\rho\) converges. The following lemmas are properties of the function \(f(\rho)\) and the consequences of this iterative process.