diff --git a/curvesim/pipelines/templates.py b/curvesim/pipelines/templates.py index 39a5975a2..dadb6b9b1 100644 --- a/curvesim/pipelines/templates.py +++ b/curvesim/pipelines/templates.py @@ -3,6 +3,30 @@ def run_pipeline(param_sampler, price_sampler, strategy, ncpu=4): + """ + Core function for running pipelines. + + Parameters + ---------- + param_sampler : iterator + An terator that returns pool parameters (see :mod:`.param_samplers`). + + price_sampler : iterator + An iterator that returns (minimally) a time-series of prices + (see :mod:`.price_samplers`). + + strategy: callable + A function dictating what happens at each timestep. + + ncpu : int, default=4 + Number of cores to use. + + Returns + ------- + results : tuple + Contains the metrics produced by the strategy. + + """ if ncpu > 1: price_sampler_data = [d for d in price_sampler] args = [(pool, params, price_sampler_data) for pool, params in param_sampler] @@ -21,7 +45,28 @@ def run_pipeline(param_sampler, price_sampler, strategy, ncpu=4): class SimInterface: + """ + A template class for creating simulation interfaces for pools. + See pool.stablewap.interfaces.StableSwapSimInterface + + This component is likely to change. + """ + def _set_pool_interface(self, pool, pool_function_dict): + """ + Binds the pool and functions used in simulation to the interface. + + Parameters + ---------- + pool : + A pool object. + + pool_function_dict : dict + A dict with interface method names as keys, and functions as values. + + Note: Currently, _get_pool_state, and _init_coin_indices are required. + + """ self.pool = pool pool_function_dict = pool_function_dict.copy() @@ -38,17 +83,31 @@ def _set_pool_interface(self, pool, pool_function_dict): self.set_pool_state() def get_pool_state(self): + """ + Gets pool state using the provided _get_pool_state method + """ return self._get_pool_state(self.pool) def set_pool_state(self): + """ + Records the current pool state in the interface's pool_state atttribute. + """ self.pool_state = self.get_pool_state() def get_coin_indices(self, *coins): + """ + Gets the pool indices for the input coin names. + Uses the coin_indices set by _init_coin_indices. + """ coin_indices = self.coin_indices return [self._get_coin_index(coin_indices, c) for c in coins] @staticmethod def _get_coin_index(coin_indices, coin_id): + """ + Gets the index for a single coin based on its name. + Uses the coin_indices set by _init_coin_indices. + """ if isinstance(coin_id, str): coin_id = coin_indices[coin_id] return coin_id diff --git a/curvesim/pipelines/utils.py b/curvesim/pipelines/utils.py index 5c973a6bd..b15493e44 100644 --- a/curvesim/pipelines/utils.py +++ b/curvesim/pipelines/utils.py @@ -5,6 +5,33 @@ # Volume Multipliers def compute_volume_multipliers(pool_vol, market_vol, n, pool_type, mode=1): + """ + Computes volume multipliers (vol_mult) used for volume limiting. + + Parameters + ---------- + pool_vol : numpy.ndarray + Total volume for the pool over the simulation period. + + market_vol : numpy.ndarray + Total market volume for each token pair over the simulation period. + + n : int + The number of token-types in the pool (e.g., DAI, USDC, USDT = 3) + + pool_type : str + "Pool" or "MetaPool" + + vol_mode : int, default=1 + Modes for computing the volume multiplier: + + 1: limits trade volumes proportionally to market volume for each pair + + 2: limits trade volumes equally across pairs + + 3: mode 2 for trades with meta-pool asset, mode 1 for basepool-only trades + + """ if pool_type == "Pool": vol_mult = pool_vol_mult(pool_vol, market_vol, n, mode)