Skip to content

Commit

Permalink
Wrapup pipeline docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nagakingg authored and chanhosuh committed Nov 8, 2022
1 parent 1356358 commit f1a9ee4
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
59 changes: 59 additions & 0 deletions curvesim/pipelines/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()

Expand All @@ -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
27 changes: 27 additions & 0 deletions curvesim/pipelines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f1a9ee4

Please sign in to comment.