Closed nagakingg closed 1 year ago
re: Trade
objects, maybe we can extend to ArbTrade
which has a price_target
attribute.
I would agree we should cleanup the function. It is rather lengthy, which is why there are explanatory comments. These shouldn't really be necessary if there are smaller functions properly named with helpful signatures.
Version Information
All curvesim versions for all Python versions and OSs
What's your issue about?
In the volume limited arbitrage pipeline, when a trading pair is limited to 0 volume, the trading size for that pair is still included as a free parameter to estimate in
multipair_optimal_arbitrage
. This can causescipy.optimize.least_squares
to hang or raise a ValueError "'x' is not within the trust region".How can it be fixed?
Any trade with a size limit less than a pool's minimum trade size will never be executed during optimization, so they can be excluded from the
least_squares
optimization. When there are no eligible trades, optimization can/should be skipped.The most simple adjustment is this, but:
To do this more cleanly, I propose: 1) Reorganize the above proposed code:
least_squares
2) Introduce a get_price_error() function that combines the price errors returned by
least_squares
with price errors for any excluded pairsres.fun
(i.e.,post_trade_price_error_multi
for the optimized trades, taken fromleast_squares
results object)post_trade_price_error_multi
for a series of null trades:get_price_error(err.fun, skipped_pairs)
could concat optimizer results (if any) with the null trades method (if needed) to handle all cases (i.e., all pairs traded, some pairs traded, no pairs traded, optimizer error)