bourse.step_sim.run(env: StepEnv | StepEnvNumpy, agents: Iterable, n_steps: int, seed: int, show_progress: bool = True, use_numpy: bool = False) dict[str, ndarray]

Run a discrete event simulation for fixed number of steps

Runs a discrete event simulation. Each step of the simulation agents submit transactions to the simulation environment. At the end of the transactions are randomly shuffled and process, updating the state of the market.

Examples

market_data = bourse.step_sim.run(
    env,     # Simulation environment
    agents,  # List of agents
    50,      # Number of steps
    101      # Random seed
)
Parameters:
env: StepEnv | StepEnvNumpy

Step updating simulation environment

agents: Iterable

Iterable containing initialised agents. Agents should have an update method that interacts with the simulation environment, or if use_numpy is True then agents should return a tuple of Numpy array instructions. See bourse.step_sim.agents.base_agent.BaseAgent and bourse.step_sim.agents.base_agent.BaseNumpyAgent for more details.

n_steps: int

Number of simulation steps to run.

seed: int

Random seed.

show_progress: bool = True

If True a progress bar will be displayed, default True

use_numpy: bool = False

If True use numpy api to for market state and to submit market instructions. Default False

Returns:

dict – Dictionary containing level 2 market data with keys:

  • bid_price: Bid price at each step

  • ask_price: Ask price at each step

  • bid_vol: Total bid volume at each step

  • ask_vol: Total ask volume at each step

  • trade_vol: Trade volume each step

  • bid_vol_<N>: Bid volume at top 10 levels at each step

  • ask_vol_<N>: Ask volume at top 10 levels at each step

  • n_bid_<N>: Number of bid orders at top 10 levels at each step

  • n_ask_<N>: Number of ask orders at top 10 levels at each step