# How can I calculate the amount of volume to use to ensure highest profit on an arbitrage trade of two Constant Product Market Making exchanges? [closed]

If there exists an arbitrage opportunity between two Constant Product Market Making exchanges, how can you confidently determine the maximum volume to use in order to ensure highest profit?

I can imagine incrementing and testing various values, but it seems extremely inneficient.

As an example:

These exchanges do not have an orderbook, but rather provide a varying rate that depends upon the volume of the input. A rough example would be the following:

If I were to buy 1 share of AAPL, I would get it for $174.13. If I were to buy 2 shares of AAPL, I would get it for less, maybe$174.10.

The rates are derived from the amount of liquidity in the market (imagine a pool of AAPL stock). If there are 1000 AAPL in the pool, and you tried to buy 999 of them, the price would be in the millions of dollars, because you will have effectively depleted the pool.

## closed as unclear what you're asking by madilyn, skoestlmeier, Helin, Attack68♦, LlianeMar 6 at 8:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.