# Calculating most profitable arbitrage orders on multiple market with fixed and variable fees

If I have multiple markets (let's say 5, but the solution should be generic) trading the same stock/commodity/whatever, and the markets differ in both variable fees (which are in % of the trade order) and fix fees (which are in absolute number of $per trade order), and suppose there exists an arbitrage opportunity on more than 2 markets at the same time, how do you calculate the absolutely most profitable sequence of market orders? (order of orders matters) The variable fees are not a problem, but the fix fees complicate the whole algorithm tremendously. Is this a traveling salesman type of problem? Or, is there any paper which deals with this problem. The fees might be something like this (shown as an example): • 1st market:$5 + 1 %

• 2nd market: $4 + 2 % • 3rd market:$0 + 5 %

• 4th market: $10 + 0 % • 5th market:$3 + 3 %

-
I find your question slightly confusing. Why you need more than 2 markets to present an arbitrage opportunity, 2 or more are already sufficient. And why is it complicated to add in your execution related fees, whether stated as a percentage of notional traded or as fixed fee per trade? –  Matt Wolf Jul 10 '13 at 1:20
Example: Market1(fixed fee: 1, variable fee: 2%, BBO: 105/107), Market2(fixed fee: 0.5, variable fee 1%, BBO: 98/100). Variable Fees -> Buy asset at M2 for (100 + 1) and sell to M1 for (105-2.1). PnL with fixed fees applied: (105-0.5) - (100+1). -> Apply same logic to all markets and chose the most profitable one. –  Matt Wolf Jul 10 '13 at 1:27
Well, the idea is that the arbitrage opportunity can be at more than 2 markets at the same time. And the market depth at each exchange is finite IN VOLUME. What I mean is that at price 107, there might be only 3 pieces of the stock. –  Paya Jul 10 '13 at 2:00
that does not change the kind of algorithm you need to run the markets over. You need to include your all-in execution related costs and may find out that low volume will not push you over the "hurdle-rate", which may rank this particular arbitrage lower or even net-unprofitable. –  Matt Wolf Jul 10 '13 at 3:37
Have you made any progress on this question? Is there anything in my answer which you have trouble following? –  Tyler Jul 15 '13 at 6:18

Assume $n$ markets where each market $n$ has features $Bid(n)$, $Ask(n)$, bid volume, $BidV(n)$, ask volume, $AskV(n)$, fixed costs, $FixC(n)$, and variable costs, $VarC(n)$. Assume you buy on market $n$ and sell on market $n+1$. The profit $\Pi(n,n+1)$ of each arbitrage opportunity amounts to

$$\Pi(n,n+1) = V * [(1+VarC(n+1))*Bid(n+1) - (1+VarC(n))*Ask(n)] + FixC(n+1) - FixC(n)$$

where

$$V = \min(AskV(n),BidV(n+1))$$

You can't buy in market $n$ more than you can sell in market $n+1$. You can only trade the smallest value of the two.

To maximize the amount you make overall you obviously need to maximize the amount you make per trade. However, it's important to notice that maximizing the $\Pi$ above will not necessarily maximize your overall return. $\Pi$ goes up with volume. You're not interested however in trading the largest amounts but rather those amounts that produce the biggest returns on your money.

So to properly rank your two market arbitrage bundles among all bundles you need to use something like $\Pi/V$ or even better something like $\frac{\Pi}{(1+VarC(n))*V*Ask(n) + FixC(n)}$ which amounts to return over investment including costs.

This should be easy to understand but in case there's trouble you can think about a numerical example like the following. Market three buys volume $180$ at $\$6$. Market two sells$180$at$\$3$. Market one sells $20$ at $\$2$. Arbitraging on market two and three yields higher values of$\Pi$but lower values of$\Pi/V$. As such you should first trade the$20$volume on the$(1,3)$bundle and then trade$160$on the$(2,3)$bundle. Obviously, the goal here is to lower your average purchasing price. Beyond this small ranking step however your algorithm doesn't need much more. At each step, first of all, rank each arbitrage bundle on its$\Pi/V$score, second of all, trade the highest$\Pi/V\$ one, and finally update the volume levels for the traded markets. Rinse, lather, repeat until there's no volume left for arbitraging.

Don't know if you can express the final overall PnL in one single mathematical sentence but it shouldn't be too hard to set up in the programming language of your choice.

-
Sorry for my late reply. I think the profit equation should actually be "V*[Bid(n+1) * (1 - VarC(N+1)) - Ask(n) * (1 + VarC(n))] - FixC(n+1) − FixC(n)". Which should equal to the more readable expression "V*Bid(n+1) - V*Ask(n) - V*Bid(n+1)*VarC(n+1) - V*Ask(n)*VarC(n) - FixC(n+1) − FixC(n)". But thanks a lot for your valuable answer, I will have to think hard about this one and maybe do some experiments to verify the algorithm. –  Paya Feb 19 at 19:01
Not sure if this handles corner cases. A special case like this might appear, as you execute the algorithm on each entry: the algorithm identifies as ideal trading exchage1->exchange3 of maximum volume, then exchange1->exchange2 for the rest, and lastly exchange4->exchange2. However, since the algorithm considers costs only on a per-entry scale rather than in complex manner, it might be actually more profitable to merge first and second trade and execute the combined volume on exchange1->exchange2, because of transaction savings implied from merging trades across book order entries. –  Paya Feb 19 at 19:15