Run a basic market simulation with a noise agent. This function creates a simplified market environment with a single agent that generates random order flow. The simulation runs for a specified time period and then visualizes the resulting price trajectory. Args: seed: Rand
(seed: int = 0)
| 17 | |
| 18 | |
| 19 | def run_basic_simulation(seed: int = 0) -> None: |
| 20 | """Run a basic market simulation with a noise agent. |
| 21 | |
| 22 | This function creates a simplified market environment with a single agent |
| 23 | that generates random order flow. The simulation runs for a specified time period |
| 24 | and then visualizes the resulting price trajectory. |
| 25 | |
| 26 | Args: |
| 27 | seed: Random seed for reproducible simulation results |
| 28 | |
| 29 | Returns: |
| 30 | None |
| 31 | """ |
| 32 | # Setup simulation parameters |
| 33 | symbols = ["000000"] |
| 34 | start_time = Timestamp("2024-01-01 09:30:00") |
| 35 | end_time = Timestamp("2024-01-01 10:30:00") |
| 36 | |
| 37 | # Create exchange environment |
| 38 | exchange_config = create_exchange_config_without_call_auction( |
| 39 | market_open=start_time, |
| 40 | market_close=end_time, |
| 41 | symbols=symbols, |
| 42 | ) |
| 43 | exchange = Exchange(exchange_config) |
| 44 | |
| 45 | # Initialize noise agent for order generation |
| 46 | agent = NoiseAgent( |
| 47 | symbol=symbols[0], |
| 48 | init_price=100000, |
| 49 | interval_seconds=1, |
| 50 | start_time=start_time, |
| 51 | end_time=end_time, |
| 52 | seed=seed, |
| 53 | ) |
| 54 | |
| 55 | # Configure simulation environment |
| 56 | exchange.register_state(TradeInfoState()) |
| 57 | env = Env(exchange=exchange, description="Noise agent simulation") |
| 58 | env.register_agent(agent) |
| 59 | env.push_events(create_exchange_events(exchange_config)) |
| 60 | |
| 61 | # Run simulation |
| 62 | for observation in env.env(): |
| 63 | action = observation.agent.get_action(observation) |
| 64 | env.step(action) |
| 65 | |
| 66 | # Extract and visualize results |
| 67 | trade_infos: list[TradeInfo] = extract_trade_information(exchange, symbols[0], start_time, end_time) |
| 68 | logging.info(f"Collected {len(trade_infos)} trade information records.") |
| 69 | visualize_price_trajectory(trade_infos, Path("tmp/price_curves.png")) |
| 70 | |
| 71 | |
| 72 | def extract_trade_information(exchange: Exchange, symbol: str, start_time: Timestamp, end_time: Timestamp) -> list[TradeInfo]: |
no test coverage detected