From d74df4929a4a7e2c4b8a758f347b5433fe5bd9cc Mon Sep 17 00:00:00 2001 From: naga Date: Fri, 7 Jul 2023 12:20:44 -0400 Subject: [PATCH] Update logs --- curvesim/iterators/__init__.py | 2 +- curvesim/iterators/param_samplers/__init__.py | 12 +++++-- curvesim/iterators/param_samplers/grid.py | 12 +++++++ .../iterators/price_samplers/price_volume.py | 4 +-- curvesim/templates/__init__.py | 4 +-- .../{param_sampler.py => param_samplers.py} | 31 +++++++++++-------- .../{price_sampler.py => price_samplers.py} | 0 docs/api.rst | 26 ++++++++++++++-- docs/logs/20230518.log | 0 9 files changed, 69 insertions(+), 22 deletions(-) rename curvesim/templates/{param_sampler.py => param_samplers.py} (84%) rename curvesim/templates/{price_sampler.py => price_samplers.py} (100%) create mode 100644 docs/logs/20230518.log diff --git a/curvesim/iterators/__init__.py b/curvesim/iterators/__init__.py index b15bc74d0..625d8b8e5 100644 --- a/curvesim/iterators/__init__.py +++ b/curvesim/iterators/__init__.py @@ -6,7 +6,7 @@ Iterators fall into two general categories: 1. :mod:`.param_samplers`: - Generate pool with updated parameters per tick. + Generate pools with updated parameters per run. 2. :mod:`.price_samplers`: Generate price, volume, and/or other time-series data per tick. """ diff --git a/curvesim/iterators/param_samplers/__init__.py b/curvesim/iterators/param_samplers/__init__.py index d22b14082..9981fbdfd 100644 --- a/curvesim/iterators/param_samplers/__init__.py +++ b/curvesim/iterators/param_samplers/__init__.py @@ -1,9 +1,17 @@ """ -Iterators that generate pools with updated parameters per simulation run. +Iterators that generate pools with updated parameters for each simulation run. """ +__all__ = [ + "Grid", + "CurvePoolGrid", + "CurveMetaPoolGrid", + "CurveCryptoPoolGrid", + "get_param_sampler", +] + from curvesim.pool.sim_interface import SimCurvePool, SimCurveRaiPool, SimCurveMetaPool -from .grid import CurvePoolGrid, CurveMetaPoolGrid +from .grid import Grid, CurvePoolGrid, CurveMetaPoolGrid, CurveCryptoPoolGrid pool_param_sampler_map = { diff --git a/curvesim/iterators/param_samplers/grid.py b/curvesim/iterators/param_samplers/grid.py index 0f84ded0a..da5456aa7 100644 --- a/curvesim/iterators/param_samplers/grid.py +++ b/curvesim/iterators/param_samplers/grid.py @@ -37,12 +37,24 @@ def make_parameter_sequence(self, variable_params): class CurvePoolGrid(Grid, CurvePoolMixin): + """ + :class:`Grid` parameter sampler specialized for Curve pools. + """ + pass class CurveMetaPoolGrid(Grid, CurveMetaPoolMixin): + """ + :class:`Grid` parameter sampler specialized for Curve meta-pools. + """ + pass class CurveCryptoPoolGrid(Grid, CurveCryptoPoolMixin): + """ + :class:`Grid` parameter sampler specialized for Curve meta-pools. + """ + pass diff --git a/curvesim/iterators/price_samplers/price_volume.py b/curvesim/iterators/price_samplers/price_volume.py index 8a68c677e..edb017372 100644 --- a/curvesim/iterators/price_samplers/price_volume.py +++ b/curvesim/iterators/price_samplers/price_volume.py @@ -1,6 +1,6 @@ from curvesim.logging import get_logger from curvesim.price_data import get -from curvesim.templates.price_sampler import PriceSample, PriceSampler +from curvesim.templates.price_samplers import PriceSample, PriceSampler from curvesim.utils import dataclass, override logger = get_logger(__name__) @@ -64,7 +64,7 @@ def __iter__(self) -> PriceVolumeSample: """ Yields ------- - class:`PriceVolumeSample` + :class:`PriceVolumeSample` """ for price_row, volume_row in zip( self.prices.iterrows(), self.volumes.iterrows() diff --git a/curvesim/templates/__init__.py b/curvesim/templates/__init__.py index 4c920385f..fcf3dbf61 100644 --- a/curvesim/templates/__init__.py +++ b/curvesim/templates/__init__.py @@ -15,8 +15,8 @@ "PriceSampler", ] -from .param_sampler import DynamicParameterSampler, SequentialParameterSampler -from .price_sampler import PriceSample, PriceSampler +from .param_samplers import DynamicParameterSampler, SequentialParameterSampler +from .price_samplers import PriceSample, PriceSampler from .sim_assets import SimAssets from .sim_pool import SimPool from .strategy import Strategy diff --git a/curvesim/templates/param_sampler.py b/curvesim/templates/param_samplers.py similarity index 84% rename from curvesim/templates/param_sampler.py rename to curvesim/templates/param_samplers.py index 0eec03bd5..9a3e66af7 100644 --- a/curvesim/templates/param_sampler.py +++ b/curvesim/templates/param_samplers.py @@ -30,8 +30,8 @@ def set_pool_attributes(self, pool, attribute_dict): """ Sets the pool attributes defined in attribute_dict. - Supports setting attributes with setattr(pool, key, value) or specialized - setters defined in the 'setters' property: + Supports setting attributes with :python:`setattr(pool, key, value)` or + specialized setters defined in the 'setters' property: :python:`self.setters[key](pool, value)` For metapools, basepool parameters can be referenced by appending "_base" to @@ -76,8 +76,8 @@ def _set_pool_attribute(self, pool, attr, value): """ Sets a single pool attribute. - Supports setting attributes with setattr(pool, attr, value) or specialized - setters defined in the 'setters' property: + Supports setting attributes with :python:`setattr(pool, attr, value)` or + specialized setters defined in the 'setters' property: :python:`self.setters[attr](pool, value)` Parameters @@ -109,6 +109,10 @@ def _set_pool_attribute(self, pool, attr, value): class SequentialParameterSampler(ParameterSampler): + """ + Parameter sampler that yields pools using a fixed sequence of parameters. + """ + def __init__(self, pool, variable_params, fixed_params=None): """ Parameters @@ -119,22 +123,19 @@ def __init__(self, pool, variable_params, fixed_params=None): variable_params: dict Pool parameters to vary across simulations. - Keys: pool parameters, Values: iterable of values - - For metapools, basepool parameters can be referenced by appending "_base" to - an attribute's name. + Keys are parameter names and values are iterables of values. For metapools, + basepool parameters can be referenced by appending "_base" to an attribute + name. Example - ------- + -------- .. code-block :: - {"A": [100, 1000], "basepool": {fee: [10**6, 4*10**6]}} + {"A": [100, 1000], "fee_base": [10**6, 4*10**6]} fixed_params : dict, optional Pool parameters set before all simulations. - Keys: pool parameters, Values: single values - """ self.pool_template = deepcopy(pool) self.set_pool_attributes(self.pool_template, fixed_params) @@ -144,7 +145,7 @@ def __iter__(self): """ Yields ------- - pool : pool object + pool : :class:`~curvesim.templates.SimPool` A pool object with the current variable parameters set. params : dict @@ -175,5 +176,9 @@ def make_parameter_sequence(self, variable_params): class DynamicParameterSampler(ParameterSampler): + """ + Parameter sampler that selects parameters dynamically based on simulation results. + """ + def __init__(self): raise NotImplementedError diff --git a/curvesim/templates/price_sampler.py b/curvesim/templates/price_samplers.py similarity index 100% rename from curvesim/templates/price_sampler.py rename to curvesim/templates/price_samplers.py diff --git a/docs/api.rst b/docs/api.rst index 2cd882ccd..cc586c55a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -155,10 +155,32 @@ Iterators ------------------ .. automodule:: curvesim.iterators.param_samplers + Abstract + ^^^^^^^^^ + .. autoclass:: curvesim.templates.param_samplers.ParameterSampler + :members: + :special-members: __iter__ + + .. autoclass:: curvesim.templates.param_samplers.SequentialParameterSampler + :special-members: __iter__ + :inherited-members: + + Concrete + ^^^^^^^^^ .. autoclass:: curvesim.iterators.param_samplers.Grid :special-members: __iter__ :inherited-members: + .. autoclass:: curvesim.iterators.param_samplers.CurvePoolGrid + :exclude-members: __new__ + + .. autoclass:: curvesim.iterators.param_samplers.CurveMetaPoolGrid + :exclude-members: __new__ + + .. autoclass:: curvesim.iterators.param_samplers.CurveCryptoPoolGrid + :exclude-members: __new__ + + Price Samplers -------------- @@ -167,11 +189,11 @@ Iterators Abstract ^^^^^^^^^ - .. autoclass:: curvesim.templates.samplers.PriceSampler + .. autoclass:: curvesim.templates.price_samplers.PriceSampler :members: :special-members: __iter__ - .. autoclass:: curvesim.templates.samplers.PriceSample + .. autoclass:: curvesim.templates.price_samplers.PriceSample :members: :exclude-members: __init__, __new__ diff --git a/docs/logs/20230518.log b/docs/logs/20230518.log new file mode 100644 index 000000000..e69de29bb