Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify autosim/pipeline vol_mult interface #198

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/20230809_155432_nagakingg_vol-mult-fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changed
-------
- Fixed discrepency between vol_mult arg in auto_sim vs. pipelines
18 changes: 13 additions & 5 deletions curvesim/sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from curvesim.pipelines.vol_limited_arb import DEFAULT_PARAMS
from curvesim.pipelines.vol_limited_arb import pipeline as volume_limited_arbitrage
from curvesim.pool_data import get_metadata
from curvesim.utils import get_pairs

logger = get_logger(__name__)

Expand Down Expand Up @@ -114,12 +115,15 @@ def autosim(
data_dir: str, default='data'
Relative path to saved data folder.

vol_mult : float or numpy.ndarray, default computed from data
vol_mult : dict, float, or int, default computed from data
Value(s) multiplied by market volume to specify volume limits
(overrides vol_mode).

Can be a scalar or vector with values for each pairwise coin
combination.
dict should map from trade-pair tuples to values, e.g.:

.. code-block::

{('DAI', 'USDC'): 0.1, ('DAI', 'USDT'): 0.1, ('USDC', 'USDT'): 0.1}

vol_mode : int, default=1
Modes for limiting trade volume.
Expand All @@ -138,7 +142,7 @@ def autosim(
assert any([pool, pool_metadata]), "Must input 'pool' or 'pool_metadata'"

pool_metadata = pool_metadata or get_metadata(pool, chain)
p_var, p_fixed, kwargs = _parse_arguments(**kwargs)
p_var, p_fixed, kwargs = _parse_arguments(pool_metadata, **kwargs)

results = volume_limited_arbitrage(
pool_metadata,
Expand All @@ -151,7 +155,7 @@ def autosim(
return results


def _parse_arguments(**kwargs):
def _parse_arguments(pool_metadata, **kwargs):
pool_args = ["A", "D", "x", "p", "fee", "fee_mul", "tokens", "admin_fee"]
pool_args += [arg + "_base" for arg in pool_args[:-1]]

Expand All @@ -174,6 +178,10 @@ def _parse_arguments(**kwargs):
else:
raise TypeError(f"Argument {key} must be an int or iterable of ints")

elif key == "vol_mult" and isinstance(val, (int, float)):
coin_pairs = get_pairs(pool_metadata.coin_names)
rest_of_params[key] = dict.fromkeys(coin_pairs, val)

else:
rest_of_params[key] = val

Expand Down
Loading