The basic principle is this, given three currencies ($x$, $y$, $z$), and the exchange rates between the three ( $x_r$, $y_r$, $z_r$), if $ x_r * y_r * z_r > 1 $ then an arbitrage opportunity exists.
This can then be phrased in terms of a graph by first inverting
$$ 1 / (x_r * y_r * z_r) < 1 $$
and then taking the natural log, which gives
$$ log(1 / x_r ) + log(1 / y_r) + log( 1/ z_r) < 0 $$
I can then weight the edges of the graph with these values and expect it to give me the correct result.
The trouble I'm having is factoring trade fees (which is a constant percentage e.g. 0.02%) into this. What I've figured is if
$$ (x_r - x_r*fee)* (y_r - y_r*fee) * (z_r - z_r*fee) > 1 $$
then there is an opportunity. So it follows that
$$ log(1 / (x_r *(1 - fee)) ) + log(1 /( y_r*(1 - fee))) + log( 1/ (z_r*(1 - fee)) ) < 0 $$ However using these values as my edge weights gives the wrong results.
How can I properly take fees into account?