Skip to content

Commit

Permalink
feat: default price process fn
Browse files Browse the repository at this point in the history
* feat: deprecate RW_model and GBM_model

* feat: update ConfigurableMarket scenario

* feat: update IdealMarketMaker scenario

* feat: update MarketCrash scenario

* feat: update VegaLoadTest scenario

* fix: increase price_process length

* feat: update default price_process_fn for integration tests

* refactor: remove network scenario

* feat: remove fairground scenario

* fix: remove missing imports
  • Loading branch information
cdummett authored Nov 21, 2022
1 parent 80e5af7 commit 3dd08b0
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 752 deletions.
8 changes: 8 additions & 0 deletions tests/integration/test_parameter_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import vega_sim.parameter_test.parameter.experiment as experiment
from vega_sim.parameter_test.parameter.configs import CONFIGS
from vega_sim.scenario.common.utils.price_process import random_walk


@pytest.mark.integration
Expand All @@ -15,6 +16,13 @@ def test_parameter_runner(experiment_to_run: experiment.SingleParameterExperimen
experiment_to_run.runs_per_scenario = (
1 # Likely only need to test the one run per scenario
)

experiment_to_run.scenario.price_process_fn = lambda: random_walk(
num_steps=experiment_to_run.scenario.num_steps,
starting_price=1000,
sigma=0.1,
)

results = experiment.run_single_parameter_experiment(experiment_to_run)
experiment.output_logs(
results,
Expand Down
2 changes: 1 addition & 1 deletion vega_sim/scenario/common/utils/price_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def random_walk(
random_state_set = random_state is not None
random_state = random_state if random_state_set else np.random.RandomState()

S = np.zeros(num_steps)
S = np.zeros(num_steps + 1)
S[0] = starting_price

for _ in range(100):
Expand Down
13 changes: 4 additions & 9 deletions vega_sim/scenario/comprehensive_market/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from vega_sim.environment.agent import Agent

from vega_sim.scenario.scenario import Scenario
from vega_sim.scenario.ideal_market_maker_v2.utils.price_process import RW_model
from vega_sim.scenario.common.utils.price_process import random_walk
from vega_sim.environment.environment import MarketEnvironmentWithState
from vega_sim.null_service import VegaServiceNull
from vega_sim.scenario.constants import Network
Expand All @@ -32,7 +32,6 @@ class ComprehensiveMarket(Scenario):
def __init__(
self,
num_steps: int = 1000,
dt: float = 1 / 60 / 24 / 365.25,
market_decimal: int = 5,
asset_decimal: int = 5,
market_position_decimal: int = 2,
Expand Down Expand Up @@ -76,7 +75,6 @@ def __init__(
num_momentum_agents: int = 1,
):
self.num_steps = num_steps
self.dt = dt
self.market_decimal = market_decimal
self.asset_decimal = asset_decimal
self.market_position_decimal = market_position_decimal
Expand Down Expand Up @@ -141,15 +139,12 @@ def _generate_price_process(
self,
random_state: Optional[np.random.RandomState] = None,
):
_, price_process = RW_model(
T=self.num_steps * self.dt,
dt=self.dt,
mdp=self.market_decimal,
return random_walk(
num_steps=self.num_steps,
sigma=self.sigma,
Midprice=self.initial_price,
starting_price=self.initial_price,
random_state=random_state,
)
return price_process

def set_up_background_market(
self,
Expand Down
9 changes: 7 additions & 2 deletions vega_sim/scenario/configurable_market/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
)

from vega_sim.scenario.scenario import Scenario
from vega_sim.scenario.ideal_market_maker_v2.utils.price_process import RW_model
from vega_sim.environment.environment import MarketEnvironmentWithState
from vega_sim.null_service import VegaServiceNull
from vega_sim.scenario.constants import Network
Expand Down Expand Up @@ -53,6 +52,7 @@ def __init__(
Callable[[VegaServiceNull, List[Agent]], Any]
] = None,
settle_at_end: bool = True,
price_process_fn: Optional[Callable] = None,
):

# Simulation settings
Expand All @@ -61,6 +61,7 @@ def __init__(
self.block_size = block_size
self.block_length_seconds = block_length_seconds
self.settle_at_end = settle_at_end
self.price_process_fn = price_process_fn

# Logging options
self.state_extraction_freq = state_extraction_freq
Expand Down Expand Up @@ -112,7 +113,11 @@ def set_up_background_market(
market_name = self.market_name
asset_name = self.asset_name

price_process = self._generate_price_process(random_state=random_state)
price_process = (
self.price_process_fn()
if self.price_process_fn is not None
else self._generate_price_process(random_state=random_state)
)

market_manager = ConfigurableMarketManager(
proposal_wallet_name=PROPOSAL_PARTY.wallet_name,
Expand Down
13 changes: 4 additions & 9 deletions vega_sim/scenario/curve_market_maker/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

from vega_sim.scenario.scenario import Scenario
from vega_sim.scenario.ideal_market_maker_v2.utils.price_process import RW_model
from vega_sim.scenario.common.utils.price_process import random_walk
from vega_sim.environment.environment import MarketEnvironmentWithState
from vega_sim.null_service import VegaServiceNull
from vega_sim.scenario.constants import Network
Expand All @@ -35,7 +35,6 @@ def __init__(
self,
num_steps: int = 120,
random_agent_ordering: bool = True,
dt: float = 1 / 60 / 24 / 365.25,
market_decimal: int = 5,
asset_decimal: int = 5,
market_position_decimal: int = 2,
Expand Down Expand Up @@ -77,7 +76,6 @@ def __init__(

self.num_steps = num_steps
self.random_agent_ordering = random_agent_ordering
self.dt = dt
self.market_decimal = market_decimal
self.asset_decimal = asset_decimal
self.market_position_decimal = market_position_decimal
Expand Down Expand Up @@ -117,15 +115,12 @@ def _generate_price_process(
self,
random_state: Optional[np.random.RandomState] = None,
):
_, price_process = RW_model(
T=self.num_steps * self.dt,
dt=self.dt,
mdp=self.market_decimal,
return random_walk(
num_steps=self.num_steps,
sigma=self.sigma,
Midprice=self.initial_price,
starting_price=self.initial_price,
random_state=random_state,
)
return price_process

def set_up_background_market(
self,
Expand Down
36 changes: 0 additions & 36 deletions vega_sim/scenario/fairground/agents.py

This file was deleted.

Loading

0 comments on commit 3dd08b0

Please sign in to comment.