Discrete mixture distribution market intent simulator
Project description
market-wave
Aggregate market intent simulation with discrete mixture distributions.
English | 한국어
market-wave is a Python library for simulating market-wide entry and exit intent
without creating individual participants. It models aggregate buy/sell pressure,
position exits, order-book depth, cancellations, taker flow, and execution-driven
price movement on a discrete price grid.
It is not a forecasting model. It is a lightweight simulation primitive for experiments, visualization, teaching, and strategy-environment prototyping.
Why market-wave?
- Aggregate intent, not agents: market participants are represented by probability mass over price, not by individual objects.
- Discrete mixture distributions: entry and exit pressure are PMFs on the current price grid.
- Execution-driven prices: prices stay flat unless trades execute.
- Inspectable state: every step returns a
StepInfosnapshot with PMFs, volumes, order book state, position mass, VWAP, spread, and imbalance. - Built-in plotting:
matplotlibis included, with a clean light chart style by default.
Install
pip install market-wave
For local development:
git clone https://github.com/smturtle2/market-wave.git
cd market-wave
uv sync --extra dev
Python >=3.10 is supported.
Quickstart
from market_wave import Market
market = Market(initial_price=10_000, gap=10, popularity=1.0, seed=42)
steps = market.step(100)
last = steps[-1]
print(last.price_before, "->", last.price_after)
print(last.total_executed_volume)
Market.step(n) always returns list[StepInfo] and appends the same objects to
market.history.
Visualization
from market_wave import Market
market = Market(initial_price=10_000, gap=10, popularity=1.0, seed=42)
market.step(260)
fig, ax = market.plot(last=180)
The default market_wave style uses a light three-panel chart: price/VWAP,
executed volume, and order-flow imbalance. Dark overlay mode is still available:
fig, ax = market.plot(layout="overlay", style="market_wave_dark")
Core Concepts
At every step, the market builds a price grid around the current price:
price_grid = current_price +/- k * gap
The simulator maintains four probability mass functions on that grid:
buy_entry_pmfsell_entry_pmflong_exit_pmfshort_exit_pmf
Each PMF is a normalized discrete mixture:
pmf[x] = sum(component_weight * kernel(x, center_price, spread))
kernel(x, center, spread) proportional to exp(-abs(x - center) / spread)
The PMFs generate aggregate intent. The order book and execution layer then turn that intent into limit flow, taker flow, cancellations, exits, matched volume, and price changes.
Execution Guarantee
Price movement is execution-driven:
- If a step has no executed volume,
price_after == price_before. - If trades execute,
price_afteris derived from that step's execution statistics. seedmakes the simulation reproducible for the same version and inputs.
This is a simulator, not a market data replay engine and not financial advice.
API Overview
from market_wave import (
Market,
MarketState,
IntensityState,
LatentState,
MixtureComponent,
DiscreteMixtureDistribution,
DistributionState,
OrderBookState,
PositionMassState,
StepInfo,
)
Useful StepInfo fields include:
price_before,price_after,price_changebuy_entry_pmf,sell_entry_pmf,long_exit_pmf,short_exit_pmfbuy_volume_by_price,sell_volume_by_priceexecuted_volume_by_price,total_executed_volume,trade_countvwap_price,best_bid_before,best_ask_before,spread_afterorderbook_before,orderbook_afterposition_mass_before,position_mass_after
Development
uv sync --extra dev
uv run ruff check .
uv run pytest
uv build
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file market_wave-0.1.0.tar.gz.
File metadata
- Download URL: market_wave-0.1.0.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
629425349624ded571f514141804c6c4db476ac8e0fa05f9fca1d6a5b6e22790
|
|
| MD5 |
bcca1e3cd92d6b6acd7fef944465fc8c
|
|
| BLAKE2b-256 |
6b156725bfa98342a99a2bc28faf58ded1cde68a709ea6ef7c6d77bbb9e7d2f6
|
Provenance
The following attestation bundles were made for market_wave-0.1.0.tar.gz:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-0.1.0.tar.gz -
Subject digest:
629425349624ded571f514141804c6c4db476ac8e0fa05f9fca1d6a5b6e22790 - Sigstore transparency entry: 1385864914
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@b06117132b0eb4582f14678a568ce209840cff59 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@b06117132b0eb4582f14678a568ce209840cff59 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-0.1.0-py3-none-any.whl.
File metadata
- Download URL: market_wave-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3fd9113b64ec010f667d545006b0b4319467c59f57987afcec5e643b4f9dfe9
|
|
| MD5 |
8bd01694620263fdd2f1b957369234e1
|
|
| BLAKE2b-256 |
aaf22d9a23763e4b7034dcb8bf4dea1659e6a3605a04e608483b4ec688093a7f
|
Provenance
The following attestation bundles were made for market_wave-0.1.0-py3-none-any.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-0.1.0-py3-none-any.whl -
Subject digest:
e3fd9113b64ec010f667d545006b0b4319467c59f57987afcec5e643b4f9dfe9 - Sigstore transparency entry: 1385864990
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@b06117132b0eb4582f14678a568ce209840cff59 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@b06117132b0eb4582f14678a568ce209840cff59 -
Trigger Event:
push
-
Statement type: