I am trying to figure out what is the optimal compounding frequency for annual interest $\mathbf r$ and compounding count $\mathbf n$.
I calculated that for $\mathbf n \rightarrow \infty$ the compounded interest approaches $\mathbf e^r$, but compounding infinitely many times is not very practical.
Especially when the compounding must be done manually or there might be a small fixed transaction fee charged for every compounding (in cryptocurrency yield farming for example).
To start I am trying to figure out how many times do I need to compound to reach 90% of the theoretical maximum $\mathbf e^r$ so I figured I need to solve the following equation for $\mathbf n$:
$$\left( 1+\frac{r}{n}\right)^n = 0.9e^r$$
How do I do that? Using natural log does not seem to help much. Also how would I modify the equation to account for a fixed transaction fee (every time compounding is done)?
You can make a quick determination using the following inequality which holds for all $n \in \mathbb{N}$ and $r > -n$,
$$e^r \left(1 - \frac{r^2}{n}\right) \leqslant \left( 1 + \frac{r}{n}\right)^n \leqslant e^r$$
If $r = 5\%$, then $ \left( 1 + \frac{r}{n}\right)^n \geqslant e^r \left(1 - \frac{r^2}{n}\right)> 0.9 e^r$ holds for all $n >0.05^2/0.1 = 0.025$. In other words, the discretely compounded amount exceeds $0.9e^r$ in the case where $r = 5\%$ for any frequency.
Only with very high interest rates will this condition not hold for all $n \geqslant 1$. For example, if $r = 55\%$, then
$$\left( 1 + \frac{0.55}{1}\right)^1= 1.55 < 0.9e^{0.55}\approx 1.55998 < 1.625625 = \left( 1 + \frac{0.55}{2}\right)^2$$
In this case, we have $e^r \left(1 - \frac{r^2}{n}\right)> 0.9 e^r$ for $n > 0.55^2/0.1 = 3.025$. Because the bound is not extremely tight it determines that $0.9e^r$ is first exceeded when $n \geqslant 4$ when in fact this is true for $n \geqslant 2$. Nevertheless, it provides a reasonable guide.
Proof of inequality
Since $e^x \geqslant 1 +x$ and $e^{-x} \geqslant 1 - x$ for $x \geqslant 0$ we have for $r \geqslant -n$,
$$\left(1+ \frac{r}{n}\right)^n \leqslant e^{r}\leqslant \left(1- \frac{r}{n}\right)^{-n},$$
and
$$0 \leqslant e^{r} - \left(1+ \frac{r}{n}\right)^n = e^{r}\left[1 - e^{-r}\left(1+ \frac{r}{n}\right)^{n}\right]\\ \leqslant e^{r}\left[1 - \left(1- \frac{r}{n}\right)^{n}\left(1+ \frac{r}{n}\right)^{n}\right]\\= e^{r}\left[1 - \left(1- \frac{r^2}{n^2}\right)^{n}\right]$$
By Bernoulli's inequality, we have
$$\left(1- \frac{r^2}{n^2}\right)^{n}\geqslant 1 - n \cdot \frac{r^2}{n^2} = 1 - \frac{r^2}{n},$$
and it follows that
$$0 \leqslant e^{r} - \left(1+ \frac{r}{n}\right)^n \leqslant e^r \frac{r^2}{n}$$