How alejandroll10/llm_trading_sim works
This is an agent-based financial-market simulation for studying LLM trading behavior and market dynamics. Its main workflow configures a scenario, gives heterogeneous agents market information and trading decisions, matches submitted orders into trades, and records results for analysis and visualization. The README also documents multi-stock and stress scenarios, robustness sweeps, prompt variants, estimators, and plots. Several runtime modules are represented from the source index and README rather than inspected excerpts, so uncertain connections are omitted or marked dashed.
Main entry points: base_agent.py Agent state and behavior · base_sim.py Simulation runtime · match_engine.py Order matching · agent_repository.py Agent repository
Components 23
Experiments
- Scenario configuration
src/scenarios/base.py - Scenario designs
src/scenarios - Simulation runtime
src/base_sim.py
Trading agents
- Agent decision schema
src/agents/agent_types.py - Structured trade decisions
src/agents/agents_api.py - Agent state and behavior
src/agents/base_agent.py - Agent repository
src/agents/agent_manager/agent_repository.py - Rule-based strategies
src/agents/deterministic - LLM trading agent
src/agents/LLMs/llm_agent.py - Prompt and output features
src/agents/LLMs/services/schema_features.py - LLM requests
src/agents/LLMs/services/llm_services.py
Market information
- Information distribution
src/market/information/base_information_services.py - Signals and capabilities
src/market/information/information_types.py
Market execution
- Orders and commitments
src/market/orders/order.py - Order matching
src/market/engine/match_engine.py - Executed trades
src/market/trade.py - Market state
src/market/state/market_state_manager.py
Results and analysis
- Simulation logging
src/services/logging_service.py - Log records
src/services/logging_models.py - Research estimators
src/analysis - Result plots
src/visualization/plot_generator.py
Other components
- Researcher
- LLM provider
Connections 28
- Researcher → Scenario designs: selects scenario
README.md - Scenario designs → Scenario configuration: configures
src/scenarios/multi_stock.py - Scenario configuration → Simulation runtime: sets parameters
- Simulation runtime → Agent state and behavior: runs agents
- Simulation runtime → Information distribution: updates information
- Simulation runtime → Order matching: submits orders
- Agent state and behavior → Structured trade decisions: uses decisions
src/agents/base_agent.py - Structured trade decisions → Agent decision schema: defines types
src/agents/agents_api.py - Rule-based strategies → Agent state and behavior: extends behavior
- LLM trading agent → Agent state and behavior: extends behavior
src/agents/LLMs/llm_agent.py - LLM trading agent → LLM requests: requests completion
src/agents/LLMs/llm_agent.py - LLM trading agent → Prompt and output features: uses features
src/agents/LLMs/llm_agent.py - LLM requests → LLM provider: sends request
src/agents/LLMs/services/llm_services.py - Scenario configuration → LLM requests: configures endpoint
src/agents/LLMs/services/llm_services.py - Information distribution → Signals and capabilities: builds signals
src/market/information/base_information_services.py - Information distribution → Agent state and behavior: distributes signals
- Agent repository → Agent state and behavior: stores agents
src/agents/agent_manager/agent_repository.py - Order matching → Orders and commitments: processes orders
src/market/engine/match_engine.py - Order matching → Executed trades: processes trades
src/market/engine/match_engine.py - Agent repository → Orders and commitments: reads order data
src/agents/agent_manager/agent_repository.py - Agent repository → Executed trades: records trade
src/agents/agent_manager/agent_repository.py - Simulation runtime → Market state: updates market
- Order matching → Simulation logging: logs market state
src/market/engine/match_engine.py - Agent state and behavior → Simulation logging: logs agent state
src/agents/base_agent.py - Simulation logging → Log records: creates records
src/services/logging_service.py - Researcher → Research estimators: runs estimates
README.md - Research estimators → Result plots: produces figures
- Researcher → Result plots: views results
README.md