You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 cause scipy.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:
this whole section can be made cleaner
the price error output needs to be adjusted so it includes price errors for all pairs even if they are excluded from optimization
defmultipair_optimal_arbitrage(pool, prices, limits):
init_trades=get_arb_trades(pool, prices)
limited_init_trades= []
fortininit_trades:
size, pair, price_target=tlimit=int(limits[pair] *10**18)
t=min(size, limit), pair, price_target, 0, limit+1ift[0] >pool.get_min_trade_size(pair[0]): # Only include trade if it is possible for it to be executedlimited_init_trades.append(t)
ifnotlimited_init_trades: # Skip optimization if no eligible tradesreturn [], [], []
[...]
To do this more cleanly, I propose:
Reorganize the above proposed code:
Make get_arb_trades return a list of Trade objects (currently it uses amorphous tuples)
Rewrite for clarity using the Trade object attribute names
Encapsulate all into a function that returns a list of dicts that can be passed as kwargs to least_squares
Introduce a get_price_error() function that combines the price errors returned by least_squares with price errors for any excluded pairs
Currently, succesful optimization returns res.fun (i.e., post_trade_price_error_multi for the optimized trades, taken from least_squares results object)
When the optimizer fails, we return 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)
The text was updated successfully, but these errors were encountered:
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:
Reorganize the above proposed code:
least_squares
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)The text was updated successfully, but these errors were encountered: