https://github.com/cezaryklimczuk/market_simulation

Building an artificial exchange environment

https://github.com/cezaryklimczuk/market_simulation

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
Last synced: 10 months ago · JSON representation

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
Created over 1 year ago · Last pushed over 1 year ago
Metadata Files
Readme

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

  1. 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.
  2. 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.
  3. 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.
  4. 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
  5. 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.

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:

  1. 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 | sh

  • For Windows:

    powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

  • Using pip: sh pip install uv

  • Using pipx: sh pipx install uv

  1. Clone the Repository

Replace <repository_url> with your repository's URL:

sh git clone <repository_url> cd <repository_name>

  1. 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.

  1. All set! Give it a go and let me know what you think.

Owner

  • Login: CezaryKlimczuk
  • Kind: user

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)
Top Labels
Issue Labels
Pull Request Labels