# Combining discontinuous opposing returns into a single continuous function

It's my intent to measure the expected log return of the optimal trade with regards to long/short positions in a trading range. The trading range has an equilibrium where the maximal gains of the long position equate to the maximal gains of a short position which results in neither side gaining any ground. If the close price is greater than the equilibrium, use the long position as a measure of expected future returns. If it's less than the equilibrium, use the short position. If it's equal, 0.

Currently the way I've structured things, this is a discontinuous function with strong jumps around 0 which doesn't make any real world sense to me. I would rather like to see some sort of smooth transition between 0 and the regime change. I just don't know how to go about doing that. I'm also unsure if a linear mapping is reasonable or if some sort of curve/distribution would make more sense and why.

For an simple approximation (which is not particularly useful if you want values to be asymptotically close around $$N$$),

$$\ln\left(\frac{\max\left(L,H\right)}{0.01}\right)\tanh\left(k\left(x-N\right)\right)$$

or

$$\ln\left(\frac{\max\left(L,H\right)}{0.01}\right)\operatorname{erf}\left(k\left(x-N\right)\right)$$

are suitable. If you want an asymptotic approximation (which is very accurate),

$$R_{N}=\lim_{k\rightarrow\infty}R_{O}\left(1-e^{-k\left(x-N\right)^{2}}\right)$$

such that $$R_N=R_O$$, $$\forall x\in\mathbb{R}\backslash\{N\}$$ and $$R_N=0$$ when $$x=N$$. Taking large values of $$k$$, yields a continuous solution. See https://www.desmos.com/calculator/45djjacr1i. I hope this helps.

• Thank you very much! Are there any learning resources you can point me to as to how you came about this solution? I don't have a strong math background so even just general categorical subject matter would be helpful. Sep 1, 2021 at 17:06
• No problem. So, $1-e^{-k\left(x-N\right)^{2}}$ is an example of an indicator function (in this case $1$ at all points expect for $0$ at $N$). A general indicator is $\lim_{k\rightarrow\infty}\left(a-\left(a-b\right)e^{-k\left(x-N\right)^{2}}\right)$ ($a$ at all points expect for $b$ at $N$). The first two approximations were sigmoid functions (S shaped). Sigmoid functions come up when doing ODEs and indicators often come up in real world problems (i.e. Dirac delta function in physics). Sep 1, 2021 at 17:37