https://github.com/cezaryklimczuk/market_simulation
Building an artificial exchange environment
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.8%) to scientific vocabulary
Repository
Building an artificial exchange environment
Basic Info
- Host: GitHub
- Owner: CezaryKlimczuk
- Language: Python
- Default Branch: master
- Size: 130 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Market Simulation: Randomized Order Book Dynamics
This project provides a high-level simulation of a continuous-limit order book using randomly generated orders. Unlike traditional market simulators that rely on an external or “true” price feed, this approach originates prices from the random interplay of limit and market orders. In other words, the order book itself (with its evolving bids and asks) determines the trading prices, rather than referencing any exogenous data.
Overview
Purely Stochastic Price Formation
- New orders (both buys and sells) arrive according to Poisson processes, parameterized by an arrival rate ($\gamma$).
- Each order can be either limit or market, with probabilities set by a configurable ratio ($\rho$).
- There is no continuous “true” midprice feeding the simulation. Instead, the limit orders collectively create a range of possible trading prices, and market orders interact within that range.
- New orders (both buys and sells) arrive according to Poisson processes, parameterized by an arrival rate ($\gamma$).
Limit Order Book Mechanics
- The simulation maintains separate queues for bids (buy orders) and asks (sell orders).
- Orders are executed under price-time priority: the best-priced orders trade first, and if prices tie, the oldest orders match first.
- Market orders match immediately against the current best bid or ask, while limit orders may rest in the book if they do not find an immediate match.
- The simulation maintains separate queues for bids (buy orders) and asks (sell orders).
Cancellation and Lifetime
- Each limit order has a random lifetime drawn from an exponential distribution with a hazard rate \$\mu$.
- When the order’s lifetime ends, it is removed from the book if it hasn’t already executed. This keeps the simulated order book dynamic, constantly adding new orders and removing old ones.
- Each limit order has a random lifetime drawn from an exponential distribution with a hazard rate \$\mu$.
Parameter Tuning
- Arrival Rate ($\gamma$): How frequently new orders are generated.
- Hazard Rate ($\mu$): Governs the typical lifetime of orders.
- Buy-to-Sell Ratio ($\beta$): Proportion of buy orders vs. sell orders.
- Limit-to-Market Ratio ($\rho$): The chance that a new order is a limit order rather than a market order.
- Limit order exponential factor ($\lambda_L$): Determines the shape of the exponentaial function for limit order amounts.
- Market order exponential factor ($\lambda_M$): Determines the shape of the exponentaial function for market order amounts.
- Maximum halfspread ($\sigma$): Caps the maximum spread-to-mid at which limit orders can be submitted
- Arrival Rate ($\gamma$): How frequently new orders are generated.
Why Use It
- Offers a lightweight way to see how an order book evolves without external price quotes.
- Ideal for experimenting with different arrival intensities, order sizes, or cancellation dynamics, and observing emergent price formation.
- Offers a lightweight way to see how an order book evolves without external price quotes.
This project ultimately demonstrates how an order-driven market can generate its own simulated prices through the random arrivals and executions of buy and sell orders, providing a purely endogenous perspective on price discovery.
Setup guide
Follow these steps to set up your project with uv:
- Install uv
Choose one of the following installation methods. For more installation options, refer to the uv installation documentation.
Standalone Installer:
For macOS and Linux:
sh curl -LsSf https://astral.sh/uv/install.sh | shFor Windows:
powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Using pip:
sh pip install uvUsing pipx:
sh pipx install uv
- Clone the Repository
Replace <repository_url> with your repository's URL:
sh
git clone <repository_url>
cd <repository_name>
- Synchronize Dependencies
In the project directory, run:
sh
uv sync
This command will install all necessary dependencies as specified in your pyproject.toml or uv.lock file.
- All set! Give it a go and let me know what you think.
Owner
- Login: CezaryKlimczuk
- Kind: user
- Repositories: 1
- Profile: https://github.com/CezaryKlimczuk
GitHub Events
Total
- Push event: 16
- Pull request event: 4
- Create event: 3
Last Year
- Push event: 16
- Pull request event: 4
- Create event: 3
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 0
- Total pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: less than a minute
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: less than a minute
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- CezaryKlimczuk (2)