The basic question is, given $f(x) = y$ and $f(y) = z$, how can you find $x$ such that $z$ is at its maximum?

I can optimize each equation independently, but I do not know how to optimize when combining equations. A concrete example is as follows:

Imagine forex market that is made up of $x$ and $y$, where $x$ and $y$ are both currencies. Users can send in $x$ to receive $y$, and vice versa. The market structure is defined by
\begin{equation}
x * y = k
\end{equation}
where $k$ is a constant number, say $1$, and the product of $x$ and $y$ must always be equal to this number.

The price of $x$ or $y$ is simply $x / y$, such that $k$ always stays the same. If someone sends $x'$ of the currency as payment and receives $y'$ in return, the new equation for the market must be true.

\begin{equation}
\dfrac{(x + x')}{(y - y')} = k
\end{equation}

Given all this information, imagine you were to make a trade on two markets of this structure. How would you optimize your input, $x0'$, such that your output $x_1'$, is maximized, and $y_0'$ is equivalent on both trades?

$\begingroup$I kind of see what you are asking, but my instinct is saying there is a really simple mathematical way of expressing this problem but the description and choice of symbols are obfuscating it....$\endgroup$
– Attack68Mar 21 at 19:22

$\begingroup$@Attack68 I truly believe it is simple but cannot figure out how to attack it. I tried to simplify it with the first sentence.$\endgroup$
– quantfinancequestMar 21 at 19:39

$\begingroup$But then you are just optimising $z=f(f(x))$ or $f(g(x))=z$ if your 2 functions $f$ are not actually the same, so not sure where the difficulty arises (besides it not resulting in a convex or differentiable function)$\endgroup$
– Attack68Mar 21 at 19:42

$\begingroup$@Attack68 then how do you optimize $z=f(g(x))$? Is that simply a derivative of each function?$\endgroup$
– quantfinancequestMar 21 at 19:47