tradesigns 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tradesigns-1.0.0/.env.example +3 -0
- tradesigns-1.0.0/.github/workflows/ci.yml +43 -0
- tradesigns-1.0.0/.github/workflows/release.yml +45 -0
- tradesigns-1.0.0/.gitignore +25 -0
- tradesigns-1.0.0/CHANGELOG.md +34 -0
- tradesigns-1.0.0/CITATION.cff +28 -0
- tradesigns-1.0.0/CONTRIBUTING.md +58 -0
- tradesigns-1.0.0/LICENSE +21 -0
- tradesigns-1.0.0/PKG-INFO +195 -0
- tradesigns-1.0.0/README.md +164 -0
- tradesigns-1.0.0/docs/DATA.md +94 -0
- tradesigns-1.0.0/docs/boundaries.png +0 -0
- tradesigns-1.0.0/docs/bvc.png +0 -0
- tradesigns-1.0.0/docs/ladder.png +0 -0
- tradesigns-1.0.0/docs/paper.md +416 -0
- tradesigns-1.0.0/examples/make_figures.py +390 -0
- tradesigns-1.0.0/pyproject.toml +79 -0
- tradesigns-1.0.0/scripts/bar_propagation.py +134 -0
- tradesigns-1.0.0/scripts/bvc_bars.py +149 -0
- tradesigns-1.0.0/scripts/check_symbols.py +90 -0
- tradesigns-1.0.0/scripts/download_order.py +66 -0
- tradesigns-1.0.0/scripts/error_autocorr.py +49 -0
- tradesigns-1.0.0/scripts/imbalance_divergence.py +87 -0
- tradesigns-1.0.0/scripts/ingest_order.py +64 -0
- tradesigns-1.0.0/scripts/price_order.py +148 -0
- tradesigns-1.0.0/scripts/pull_day.py +114 -0
- tradesigns-1.0.0/scripts/run_bench.py +56 -0
- tradesigns-1.0.0/scripts/staleness_ladder.py +96 -0
- tradesigns-1.0.0/scripts/submit_order.py +102 -0
- tradesigns-1.0.0/src/tradesigns/__init__.py +3 -0
- tradesigns-1.0.0/src/tradesigns/bars.py +159 -0
- tradesigns-1.0.0/src/tradesigns/rules.py +98 -0
- tradesigns-1.0.0/src/tradesigns/score.py +45 -0
- tradesigns-1.0.0/tests/test_bars.py +185 -0
- tradesigns-1.0.0/tests/test_rules.py +113 -0
- tradesigns-1.0.0/tests/test_score.py +53 -0
- tradesigns-1.0.0/uv.lock +2549 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
os: [ubuntu-latest, windows-latest]
|
|
20
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v7
|
|
24
|
+
|
|
25
|
+
- name: Install uv
|
|
26
|
+
uses: astral-sh/setup-uv@v10.4.0
|
|
27
|
+
with:
|
|
28
|
+
enable-cache: true
|
|
29
|
+
|
|
30
|
+
- name: Install Python
|
|
31
|
+
run: uv python install ${{ matrix.python-version }}
|
|
32
|
+
|
|
33
|
+
- name: Sync environment
|
|
34
|
+
run: uv sync --all-extras --python ${{ matrix.python-version }}
|
|
35
|
+
|
|
36
|
+
- name: Lint
|
|
37
|
+
run: uv run ruff check .
|
|
38
|
+
|
|
39
|
+
- name: Type check
|
|
40
|
+
run: uv run mypy src
|
|
41
|
+
|
|
42
|
+
- name: Test
|
|
43
|
+
run: uv run pytest -q --cov=tradesigns
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# A release is published only through a GitHub Release, and only after the
|
|
4
|
+
# full gate set passes on the tagged commit. PyPI authentication is trusted
|
|
5
|
+
# publishing (OIDC), so no tokens are stored anywhere.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
release:
|
|
9
|
+
types: [published]
|
|
10
|
+
|
|
11
|
+
permissions: {}
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
release:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
permissions:
|
|
17
|
+
id-token: write # OIDC token for PyPI trusted publishing
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v7
|
|
21
|
+
|
|
22
|
+
- name: Install uv
|
|
23
|
+
uses: astral-sh/setup-uv@v10.4.0
|
|
24
|
+
with:
|
|
25
|
+
enable-cache: true
|
|
26
|
+
|
|
27
|
+
- name: Sync environment
|
|
28
|
+
run: uv sync --all-extras
|
|
29
|
+
|
|
30
|
+
- name: Lint
|
|
31
|
+
run: uv run ruff check .
|
|
32
|
+
|
|
33
|
+
- name: Type check
|
|
34
|
+
run: uv run mypy src
|
|
35
|
+
|
|
36
|
+
- name: Test
|
|
37
|
+
run: uv run pytest -q --cov=tradesigns
|
|
38
|
+
|
|
39
|
+
- name: Build
|
|
40
|
+
run: uv build
|
|
41
|
+
|
|
42
|
+
- name: Publish to PyPI
|
|
43
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
44
|
+
with:
|
|
45
|
+
attestations: true
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Environment secrets
|
|
2
|
+
.env
|
|
3
|
+
.env.local
|
|
4
|
+
|
|
5
|
+
# Python-generated files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[oc]
|
|
8
|
+
build/
|
|
9
|
+
dist/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv
|
|
14
|
+
|
|
15
|
+
# Test / lint caches
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
.ruff_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# Licensed market data (never commit raw or derived vendor data)
|
|
22
|
+
data/
|
|
23
|
+
*.dbn
|
|
24
|
+
*.dbn.zst
|
|
25
|
+
*.parquet
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. Versions follow
|
|
4
|
+
[SemVer](https://semver.org/), and the format follows
|
|
5
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
|
|
7
|
+
## [1.0.0] - 2026-11-28
|
|
8
|
+
|
|
9
|
+
First public release. Trade classification rules benchmarked against the
|
|
10
|
+
exchange's own aggressor flags on CME futures.
|
|
11
|
+
|
|
12
|
+
- Rules: tick, quote, Lee-Ready, and the exchange-flag ground truth
|
|
13
|
+
mapping, Polars-native and strictly causal. Every rule ships with a
|
|
14
|
+
test that mutates or appends future trades and asserts that no earlier
|
|
15
|
+
sign moved.
|
|
16
|
+
- Scoring: accuracy (plain and volume-weighted) and coverage, both
|
|
17
|
+
excluding unclassified and untagged rows by documented convention.
|
|
18
|
+
- Engines: a sign-driven twin of the clockbars imbalance rule, asserted
|
|
19
|
+
bit-identical to the library on every run and pinned by the test suite,
|
|
20
|
+
plus the adaptation-free fixed-threshold variant.
|
|
21
|
+
- Benchmark, with the data purchase recorded in `docs/DATA.md`: 34.4
|
|
22
|
+
million prints across GCZ6, NQZ6, and three WTI fronts. The at-trade
|
|
23
|
+
quote rule reaches 99.59 to 100.00 percent; one second of staleness
|
|
24
|
+
drops it to 67.32, below the tick rule's 83.65; tick-rule error
|
|
25
|
+
clusters (lag-1 autocorrelation 0.088 to 0.206); BVC's directional
|
|
26
|
+
content is exactly the sign of the bar price change and errs up to
|
|
27
|
+
37.78 percent at 5-minute bars; fixed-threshold imbalance bars keep
|
|
28
|
+
the right speed but place 92 to 94 percent of boundaries elsewhere.
|
|
29
|
+
- Paper (`docs/paper.md`) with 15 verified references and three
|
|
30
|
+
dark-theme figures regenerated from data by
|
|
31
|
+
`examples/make_figures.py`.
|
|
32
|
+
- 24 tests at 100 percent statement coverage, strict mypy, ruff clean.
|
|
33
|
+
|
|
34
|
+
[1.0.0]: https://github.com/zzionz/tradesigns/releases/tag/v1.0.0
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use tradesigns in your research, please cite it."
|
|
3
|
+
type: software
|
|
4
|
+
title: tradesigns
|
|
5
|
+
authors:
|
|
6
|
+
- alias: zzionz
|
|
7
|
+
version: 1.0.0
|
|
8
|
+
date-released: "2026-11-28"
|
|
9
|
+
license: MIT
|
|
10
|
+
repository-code: "https://github.com/zzionz/tradesigns"
|
|
11
|
+
abstract: >-
|
|
12
|
+
Trade classification rules (tick, quote, Lee-Ready, bulk volume)
|
|
13
|
+
benchmarked against CME aggressor-side flags on 34.4 million prints
|
|
14
|
+
across gold, Nasdaq-100, and WTI crude: the at-trade quote rule
|
|
15
|
+
reaches 99.59 to 100.00 percent, one second of staleness drops it
|
|
16
|
+
below the tick rule, tick-rule error clusters, BVC direction is
|
|
17
|
+
exactly the sign of the bar price change, and fixed-threshold
|
|
18
|
+
imbalance-bar boundaries are 92 to 94 percent displaced.
|
|
19
|
+
keywords:
|
|
20
|
+
- quantitative-finance
|
|
21
|
+
- market-microstructure
|
|
22
|
+
- order-flow
|
|
23
|
+
- polars
|
|
24
|
+
- financial-data
|
|
25
|
+
related-identifiers:
|
|
26
|
+
- type: url
|
|
27
|
+
value: "https://github.com/zzionz/tradesigns/blob/main/docs/paper.md"
|
|
28
|
+
description: Accompanying paper
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Small library, short rules.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/zzionz/tradesigns.git
|
|
9
|
+
cd tradesigns
|
|
10
|
+
uv sync --all-extras
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The dev environment includes clockbars (the parity target), mypy, and
|
|
14
|
+
pytest-cov. The bench extra adds databento, matplotlib, and pyarrow for
|
|
15
|
+
the scripts that touch licensed data.
|
|
16
|
+
|
|
17
|
+
## The gates
|
|
18
|
+
|
|
19
|
+
Every PR must pass all three, and CI enforces them:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv run ruff check .
|
|
23
|
+
uv run mypy src # strict
|
|
24
|
+
uv run pytest -q --cov=tradesigns # coverage stays at 100%
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
100 percent statement coverage is deliberate at the current size of the
|
|
28
|
+
library. If a line cannot be tested, the honest options are to delete it
|
|
29
|
+
or to argue for it in a PR.
|
|
30
|
+
|
|
31
|
+
## The one rule that matters
|
|
32
|
+
|
|
33
|
+
These rules classify the past from the past. Every rule and every engine
|
|
34
|
+
ships with a test that mutates or appends future trades and asserts that
|
|
35
|
+
no earlier sign or boundary moved. A change that breaks causality is not
|
|
36
|
+
a feature. A convention change (what the first trade signs, how untagged
|
|
37
|
+
prints are handled, what counts as classified) must update all three
|
|
38
|
+
artifacts in the same commit: the test that pins it, the README section
|
|
39
|
+
that states it, and the paper passage that explains why. A behavior
|
|
40
|
+
change that arrives without its documentation is a regression wearing a
|
|
41
|
+
feature's clothes.
|
|
42
|
+
|
|
43
|
+
## Data and figures
|
|
44
|
+
|
|
45
|
+
Licensed market data never enters this repository. The scripts under
|
|
46
|
+
`scripts/` recompute every number from `data/processed/`, which is
|
|
47
|
+
git-ignored; `docs/DATA.md` records what was purchased, what it cost, and
|
|
48
|
+
the vendor quirks found along the way. Figures in `docs/` are aggregates
|
|
49
|
+
regenerated by `uv run --extra bench python examples/make_figures.py`. If
|
|
50
|
+
you touch a rule or an engine, regenerate them and commit the result, so
|
|
51
|
+
the published numbers stay true.
|
|
52
|
+
|
|
53
|
+
## Reporting problems
|
|
54
|
+
|
|
55
|
+
Use the issue templates. For suspected wrong output, include the input,
|
|
56
|
+
the output, and the versions of `python`, `polars`, and `tradesigns`. Say
|
|
57
|
+
whether you believe it is a bug or an undocumented convention, since
|
|
58
|
+
those get very different fixes.
|
tradesigns-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zzionz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tradesigns
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Trade classification rules, benchmarked against exchange aggressor-side ground truth.
|
|
5
|
+
Project-URL: Homepage, https://github.com/zzionz/tradesigns
|
|
6
|
+
Project-URL: Issues, https://github.com/zzionz/tradesigns/issues
|
|
7
|
+
Author: zzionz
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: financial-data,market-microstructure,order-flow,polars,quantitative-finance
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: numpy>=1.26
|
|
24
|
+
Requires-Dist: polars>=1.0
|
|
25
|
+
Provides-Extra: bench
|
|
26
|
+
Requires-Dist: clockbars>=1.1.0; extra == 'bench'
|
|
27
|
+
Requires-Dist: databento>=0.44.0; extra == 'bench'
|
|
28
|
+
Requires-Dist: matplotlib>=3.8; extra == 'bench'
|
|
29
|
+
Requires-Dist: pyarrow>=16.0; extra == 'bench'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# tradesigns
|
|
33
|
+
|
|
34
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
35
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
36
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
37
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
38
|
+
[](https://pypi.org/project/tradesigns/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
[](https://pypi.org/project/tradesigns/)
|
|
41
|
+
|
|
42
|
+
Your order-flow measures run on signed trades. VPIN needs buys and sells per
|
|
43
|
+
volume bucket. Order-flow imbalance needs the aggressor of every print.
|
|
44
|
+
Imbalance bars need signs to know when to close. Your data almost certainly
|
|
45
|
+
does not say who initiated anything, so you sign it with the tick rule or
|
|
46
|
+
Lee-Ready and inherit accuracy numbers measured on 1990s NASDAQ.
|
|
47
|
+
|
|
48
|
+
CME futures never needed the inference. The matching engine knows which side
|
|
49
|
+
crossed the spread, because it is the matching engine, and it tags every
|
|
50
|
+
print with the aggressor's side before the tape leaves the building. We
|
|
51
|
+
scored the classical rules against that tag on 34.4 million prints across
|
|
52
|
+
gold, Nasdaq-100, and WTI crude, September to November 2026. The full study,
|
|
53
|
+
with the literature and the arithmetic behind every number below, is
|
|
54
|
+
[docs/paper.md](docs/paper.md).
|
|
55
|
+
|
|
56
|
+
Three findings, ranked by how much they should change your pipeline.
|
|
57
|
+
|
|
58
|
+
1. Against the quote that prevailed at the trade, the quote rule classifies
|
|
59
|
+
99.59 to 100.00 percent of prints correctly. On 23.2 million Nasdaq-100
|
|
60
|
+
prints it made zero errors. With at-trade quotes, the problem is solved.
|
|
61
|
+
2. One second of quote staleness drops the rule to 67.32 percent, below the
|
|
62
|
+
tick rule's 83.65. The 1990s canon was built on consolidated quotes that
|
|
63
|
+
were stale by construction. On a fresh book, the advice inverts.
|
|
64
|
+
3. With no quotes at all, the tick rule carries 16 to 28 percent error, and
|
|
65
|
+
the error runs in clusters. It flips the dominant side of a volume bucket
|
|
66
|
+
roughly one time in six on gold and one in five on crude, and it moves
|
|
67
|
+
about nine out of ten imbalance-bar boundaries.
|
|
68
|
+
|
|
69
|
+
## The scorecard
|
|
70
|
+
|
|
71
|
+
| product | prints | tick | quote at-trade | Lee-Ready |
|
|
72
|
+
| :--- | ---: | ---: | ---: | ---: |
|
|
73
|
+
| GCZ6 gold | 6.40M | 83.55% | 99.59% | 99.56% |
|
|
74
|
+
| NQZ6 Nasdaq-100 | 23.22M | 83.65% | 100.00% | 100.00% |
|
|
75
|
+
| CLX6 WTI (Sep) | 1.81M | 73.86% | 98.92% | 98.11% |
|
|
76
|
+
| CLZ6 WTI (Oct) | 1.81M | 73.76% | 98.68% | 97.87% |
|
|
77
|
+
| CLF7 WTI (Nov) | 1.12M | 72.07% | 98.54% | 97.68% |
|
|
78
|
+
|
|
79
|
+
Read the last two columns together. The Lee-Ready hybrid is dominated by the
|
|
80
|
+
pure quote rule on all five contracts; its tick-test fallback at the midpoint
|
|
81
|
+
adds error, because at-trade quotes are so good that any fallback is a
|
|
82
|
+
downgrade. Volume weighting helps the tick rule a little (crude improves from
|
|
83
|
+
26-28 percent error by count to 20-23 by volume), and the error it cannot
|
|
84
|
+
shed concentrates at the touch, where consecutive prints on an unmoved price
|
|
85
|
+
defeat the carry logic. Crude's implied and system records arrive untagged
|
|
86
|
+
(about 14 percent of prints); every number here excludes them, and both sign
|
|
87
|
+
sources face the same exclusion.
|
|
88
|
+
|
|
89
|
+
## One second old is worse than none
|
|
90
|
+
|
|
91
|
+

|
|
92
|
+
|
|
93
|
+
The at-trade quote is a gift of hindsight. Live, and in most datasets,
|
|
94
|
+
quotes arrive old, so we joined each Nasdaq-100 print to the prevailing quote
|
|
95
|
+
on a 1-second grid and added lag on top. Accuracy: 100.00 percent at trade,
|
|
96
|
+
67.32 on the grid (median effective staleness 0.65s), 61.35 at one second,
|
|
97
|
+
56.67 at five, 52.49 at a minute. The tick rule sits flat at 83.65 with no
|
|
98
|
+
quotes at all, which means every row of the ladder is below it.
|
|
99
|
+
|
|
100
|
+
The five-second figure lands exactly on the 56.7 percent a 2026 study of a
|
|
101
|
+
one-tick futures market measured for Lee-Ready under a five-second lag. Two
|
|
102
|
+
markets, two datasets, one answer, and a neat closing of the loop on 35
|
|
103
|
+
years of literature: the rules were never wrong to prefer quotes, they were
|
|
104
|
+
calibrated to quotes worth less than none. The mechanism is fast. Only 9.9
|
|
105
|
+
percent of prints see the same midpoint one grid step later. The Nasdaq-100
|
|
106
|
+
touch churns in under a second.
|
|
107
|
+
|
|
108
|
+
## What the error costs downstream
|
|
109
|
+
|
|
110
|
+
Per equal-volume bucket, the volume-clock quantity VPIN consumes, the tick
|
|
111
|
+
rule calls the wrong dominant side 14.83 percent of the time on Nasdaq-100,
|
|
112
|
+
16.41 percent on gold, and 17.96 to 21.71 percent on crude, with buy-fraction
|
|
113
|
+
correlation 0.80 to 0.88. A threshold detector built on those fractions reads
|
|
114
|
+
toxicity where there is none and misses it where there is, at exactly that
|
|
115
|
+
rate.
|
|
116
|
+
|
|
117
|
+

|
|
118
|
+
|
|
119
|
+
Bars fare no better. We drove the same fixed-threshold imbalance engine with
|
|
120
|
+
tick signs and with exchange signs, on identical streams, after asserting the
|
|
121
|
+
engine bit-identical to
|
|
122
|
+
[clockbars](https://github.com/zzionz/clockbars) itself. Signed magnitude is
|
|
123
|
+
barely inflated (1.03x on all three products tested) and bar counts nearly
|
|
124
|
+
agree (1.00 to 1.15x), so the clock keeps roughly the right speed. But 92 to
|
|
125
|
+
94 percent of boundaries land in different places: median displacement 6 to
|
|
126
|
+
32 trades, 90th percentile up to 217. Boundaries agree where flow is fast
|
|
127
|
+
and scatter where it is quiet, which is exactly where tick signs call window
|
|
128
|
+
direction wrong. The clock runs at nearly the right rate over the wrong
|
|
129
|
+
places. Anything you compute per bar is computed over a partition of the
|
|
130
|
+
stream that true signs would not have produced.
|
|
131
|
+
|
|
132
|
+
## BVC is one line of arithmetic
|
|
133
|
+
|
|
134
|
+

|
|
135
|
+
|
|
136
|
+
Bulk volume classification splits a bar's volume with Phi(dP / sigma), and
|
|
137
|
+
the literature has spent a decade disputing which sigma. The dispute never
|
|
138
|
+
touched the thing that matters: sigma is a positive scalar, so the sign of
|
|
139
|
+
Phi(dP / sigma) is always the sign of dP. BVC's directional content is
|
|
140
|
+
exactly the sign of the bar's price change. We scored both sigma
|
|
141
|
+
conventions; the wrong-direction rates are identical in every single row,
|
|
142
|
+
as the arithmetic says they must be.
|
|
143
|
+
|
|
144
|
+
That direction errs 14.90 to 30.76 percent on gold and up to 37.78 percent on
|
|
145
|
+
crude as bars grow from 1s to 5m, the opposite of the bar-size profile the
|
|
146
|
+
equities literature reports. BVC beats the tick rule only at 1-second bars
|
|
147
|
+
on crude, where the tick rule is weakest, and loses everywhere at 1m and
|
|
148
|
+
above, to a rule that is itself wrong a quarter of the time.
|
|
149
|
+
|
|
150
|
+
## The library
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
pip install tradesigns
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from tradesigns.rules import tick_rule, quote_rule, lee_ready, ground_truth
|
|
158
|
+
from tradesigns.score import accuracy, coverage
|
|
159
|
+
|
|
160
|
+
signs = tick_rule(trades) # Polars Series of +1 / -1, None where unclassified
|
|
161
|
+
truth = ground_truth(trades) # exchange flags: B -> +1, A -> -1, untagged -> None
|
|
162
|
+
print(accuracy(signs, truth)) # 0.8355 on the gold window, for example
|
|
163
|
+
print(coverage(signs, truth)) # both metrics exclude unclassified and untagged rows
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Also in the box: the imbalance engines (an adaptive twin of clockbars' rule
|
|
167
|
+
with the sign column exposed, plus an adaptation-free fixed-threshold
|
|
168
|
+
variant), and the scripts under `scripts/` that recompute every number and
|
|
169
|
+
figure in this README from the data. Nothing here is hand-copied;
|
|
170
|
+
`examples/make_figures.py` regenerates all three images. The bar engine is
|
|
171
|
+
asserted bit-identical to clockbars on every run, and the test suite pins
|
|
172
|
+
that parity on synthetic streams.
|
|
173
|
+
|
|
174
|
+
## The contract
|
|
175
|
+
|
|
176
|
+
- Strictly causal, and provably so: every rule and engine ships with a test
|
|
177
|
+
that mutates or appends future trades and asserts that no earlier sign or
|
|
178
|
+
boundary moved.
|
|
179
|
+
- 24 tests at 100 percent statement coverage, strict mypy, ruff clean, CI on
|
|
180
|
+
ubuntu and windows across Python 3.11 to 3.14.
|
|
181
|
+
- Licensed market data never enters the repository; the data ledger records
|
|
182
|
+
what was purchased and what it cost to the cent.
|
|
183
|
+
|
|
184
|
+
## Bottom line
|
|
185
|
+
|
|
186
|
+
If your feed carries the aggressor flag, use it and end the discussion. If
|
|
187
|
+
you can join quotes at the trade, the quote rule alone is near-perfect and
|
|
188
|
+
the Lee-Ready fallback only subtracts. If your quotes lag more than about a
|
|
189
|
+
second, or you have none, sign with the tick rule and be honest about it: 16
|
|
190
|
+
percent error on the index and gold products, 26 to 28 on crude, clustered
|
|
191
|
+
enough that independent-error statistics overstate your precision by an
|
|
192
|
+
order of magnitude. Do not use BVC where direction matters. And when you
|
|
193
|
+
build bars or buckets from classified signs, remember that the boundaries
|
|
194
|
+
themselves, not just the values inside them, are artifacts of the classifier
|
|
195
|
+
that signed them. The full story is in [docs/paper.md](docs/paper.md).
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# tradesigns
|
|
2
|
+
|
|
3
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/zzionz/tradesigns/actions/workflows/ci.yml)
|
|
7
|
+
[](https://pypi.org/project/tradesigns/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://pypi.org/project/tradesigns/)
|
|
10
|
+
|
|
11
|
+
Your order-flow measures run on signed trades. VPIN needs buys and sells per
|
|
12
|
+
volume bucket. Order-flow imbalance needs the aggressor of every print.
|
|
13
|
+
Imbalance bars need signs to know when to close. Your data almost certainly
|
|
14
|
+
does not say who initiated anything, so you sign it with the tick rule or
|
|
15
|
+
Lee-Ready and inherit accuracy numbers measured on 1990s NASDAQ.
|
|
16
|
+
|
|
17
|
+
CME futures never needed the inference. The matching engine knows which side
|
|
18
|
+
crossed the spread, because it is the matching engine, and it tags every
|
|
19
|
+
print with the aggressor's side before the tape leaves the building. We
|
|
20
|
+
scored the classical rules against that tag on 34.4 million prints across
|
|
21
|
+
gold, Nasdaq-100, and WTI crude, September to November 2026. The full study,
|
|
22
|
+
with the literature and the arithmetic behind every number below, is
|
|
23
|
+
[docs/paper.md](docs/paper.md).
|
|
24
|
+
|
|
25
|
+
Three findings, ranked by how much they should change your pipeline.
|
|
26
|
+
|
|
27
|
+
1. Against the quote that prevailed at the trade, the quote rule classifies
|
|
28
|
+
99.59 to 100.00 percent of prints correctly. On 23.2 million Nasdaq-100
|
|
29
|
+
prints it made zero errors. With at-trade quotes, the problem is solved.
|
|
30
|
+
2. One second of quote staleness drops the rule to 67.32 percent, below the
|
|
31
|
+
tick rule's 83.65. The 1990s canon was built on consolidated quotes that
|
|
32
|
+
were stale by construction. On a fresh book, the advice inverts.
|
|
33
|
+
3. With no quotes at all, the tick rule carries 16 to 28 percent error, and
|
|
34
|
+
the error runs in clusters. It flips the dominant side of a volume bucket
|
|
35
|
+
roughly one time in six on gold and one in five on crude, and it moves
|
|
36
|
+
about nine out of ten imbalance-bar boundaries.
|
|
37
|
+
|
|
38
|
+
## The scorecard
|
|
39
|
+
|
|
40
|
+
| product | prints | tick | quote at-trade | Lee-Ready |
|
|
41
|
+
| :--- | ---: | ---: | ---: | ---: |
|
|
42
|
+
| GCZ6 gold | 6.40M | 83.55% | 99.59% | 99.56% |
|
|
43
|
+
| NQZ6 Nasdaq-100 | 23.22M | 83.65% | 100.00% | 100.00% |
|
|
44
|
+
| CLX6 WTI (Sep) | 1.81M | 73.86% | 98.92% | 98.11% |
|
|
45
|
+
| CLZ6 WTI (Oct) | 1.81M | 73.76% | 98.68% | 97.87% |
|
|
46
|
+
| CLF7 WTI (Nov) | 1.12M | 72.07% | 98.54% | 97.68% |
|
|
47
|
+
|
|
48
|
+
Read the last two columns together. The Lee-Ready hybrid is dominated by the
|
|
49
|
+
pure quote rule on all five contracts; its tick-test fallback at the midpoint
|
|
50
|
+
adds error, because at-trade quotes are so good that any fallback is a
|
|
51
|
+
downgrade. Volume weighting helps the tick rule a little (crude improves from
|
|
52
|
+
26-28 percent error by count to 20-23 by volume), and the error it cannot
|
|
53
|
+
shed concentrates at the touch, where consecutive prints on an unmoved price
|
|
54
|
+
defeat the carry logic. Crude's implied and system records arrive untagged
|
|
55
|
+
(about 14 percent of prints); every number here excludes them, and both sign
|
|
56
|
+
sources face the same exclusion.
|
|
57
|
+
|
|
58
|
+
## One second old is worse than none
|
|
59
|
+
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
The at-trade quote is a gift of hindsight. Live, and in most datasets,
|
|
63
|
+
quotes arrive old, so we joined each Nasdaq-100 print to the prevailing quote
|
|
64
|
+
on a 1-second grid and added lag on top. Accuracy: 100.00 percent at trade,
|
|
65
|
+
67.32 on the grid (median effective staleness 0.65s), 61.35 at one second,
|
|
66
|
+
56.67 at five, 52.49 at a minute. The tick rule sits flat at 83.65 with no
|
|
67
|
+
quotes at all, which means every row of the ladder is below it.
|
|
68
|
+
|
|
69
|
+
The five-second figure lands exactly on the 56.7 percent a 2026 study of a
|
|
70
|
+
one-tick futures market measured for Lee-Ready under a five-second lag. Two
|
|
71
|
+
markets, two datasets, one answer, and a neat closing of the loop on 35
|
|
72
|
+
years of literature: the rules were never wrong to prefer quotes, they were
|
|
73
|
+
calibrated to quotes worth less than none. The mechanism is fast. Only 9.9
|
|
74
|
+
percent of prints see the same midpoint one grid step later. The Nasdaq-100
|
|
75
|
+
touch churns in under a second.
|
|
76
|
+
|
|
77
|
+
## What the error costs downstream
|
|
78
|
+
|
|
79
|
+
Per equal-volume bucket, the volume-clock quantity VPIN consumes, the tick
|
|
80
|
+
rule calls the wrong dominant side 14.83 percent of the time on Nasdaq-100,
|
|
81
|
+
16.41 percent on gold, and 17.96 to 21.71 percent on crude, with buy-fraction
|
|
82
|
+
correlation 0.80 to 0.88. A threshold detector built on those fractions reads
|
|
83
|
+
toxicity where there is none and misses it where there is, at exactly that
|
|
84
|
+
rate.
|
|
85
|
+
|
|
86
|
+

|
|
87
|
+
|
|
88
|
+
Bars fare no better. We drove the same fixed-threshold imbalance engine with
|
|
89
|
+
tick signs and with exchange signs, on identical streams, after asserting the
|
|
90
|
+
engine bit-identical to
|
|
91
|
+
[clockbars](https://github.com/zzionz/clockbars) itself. Signed magnitude is
|
|
92
|
+
barely inflated (1.03x on all three products tested) and bar counts nearly
|
|
93
|
+
agree (1.00 to 1.15x), so the clock keeps roughly the right speed. But 92 to
|
|
94
|
+
94 percent of boundaries land in different places: median displacement 6 to
|
|
95
|
+
32 trades, 90th percentile up to 217. Boundaries agree where flow is fast
|
|
96
|
+
and scatter where it is quiet, which is exactly where tick signs call window
|
|
97
|
+
direction wrong. The clock runs at nearly the right rate over the wrong
|
|
98
|
+
places. Anything you compute per bar is computed over a partition of the
|
|
99
|
+
stream that true signs would not have produced.
|
|
100
|
+
|
|
101
|
+
## BVC is one line of arithmetic
|
|
102
|
+
|
|
103
|
+

|
|
104
|
+
|
|
105
|
+
Bulk volume classification splits a bar's volume with Phi(dP / sigma), and
|
|
106
|
+
the literature has spent a decade disputing which sigma. The dispute never
|
|
107
|
+
touched the thing that matters: sigma is a positive scalar, so the sign of
|
|
108
|
+
Phi(dP / sigma) is always the sign of dP. BVC's directional content is
|
|
109
|
+
exactly the sign of the bar's price change. We scored both sigma
|
|
110
|
+
conventions; the wrong-direction rates are identical in every single row,
|
|
111
|
+
as the arithmetic says they must be.
|
|
112
|
+
|
|
113
|
+
That direction errs 14.90 to 30.76 percent on gold and up to 37.78 percent on
|
|
114
|
+
crude as bars grow from 1s to 5m, the opposite of the bar-size profile the
|
|
115
|
+
equities literature reports. BVC beats the tick rule only at 1-second bars
|
|
116
|
+
on crude, where the tick rule is weakest, and loses everywhere at 1m and
|
|
117
|
+
above, to a rule that is itself wrong a quarter of the time.
|
|
118
|
+
|
|
119
|
+
## The library
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pip install tradesigns
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from tradesigns.rules import tick_rule, quote_rule, lee_ready, ground_truth
|
|
127
|
+
from tradesigns.score import accuracy, coverage
|
|
128
|
+
|
|
129
|
+
signs = tick_rule(trades) # Polars Series of +1 / -1, None where unclassified
|
|
130
|
+
truth = ground_truth(trades) # exchange flags: B -> +1, A -> -1, untagged -> None
|
|
131
|
+
print(accuracy(signs, truth)) # 0.8355 on the gold window, for example
|
|
132
|
+
print(coverage(signs, truth)) # both metrics exclude unclassified and untagged rows
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Also in the box: the imbalance engines (an adaptive twin of clockbars' rule
|
|
136
|
+
with the sign column exposed, plus an adaptation-free fixed-threshold
|
|
137
|
+
variant), and the scripts under `scripts/` that recompute every number and
|
|
138
|
+
figure in this README from the data. Nothing here is hand-copied;
|
|
139
|
+
`examples/make_figures.py` regenerates all three images. The bar engine is
|
|
140
|
+
asserted bit-identical to clockbars on every run, and the test suite pins
|
|
141
|
+
that parity on synthetic streams.
|
|
142
|
+
|
|
143
|
+
## The contract
|
|
144
|
+
|
|
145
|
+
- Strictly causal, and provably so: every rule and engine ships with a test
|
|
146
|
+
that mutates or appends future trades and asserts that no earlier sign or
|
|
147
|
+
boundary moved.
|
|
148
|
+
- 24 tests at 100 percent statement coverage, strict mypy, ruff clean, CI on
|
|
149
|
+
ubuntu and windows across Python 3.11 to 3.14.
|
|
150
|
+
- Licensed market data never enters the repository; the data ledger records
|
|
151
|
+
what was purchased and what it cost to the cent.
|
|
152
|
+
|
|
153
|
+
## Bottom line
|
|
154
|
+
|
|
155
|
+
If your feed carries the aggressor flag, use it and end the discussion. If
|
|
156
|
+
you can join quotes at the trade, the quote rule alone is near-perfect and
|
|
157
|
+
the Lee-Ready fallback only subtracts. If your quotes lag more than about a
|
|
158
|
+
second, or you have none, sign with the tick rule and be honest about it: 16
|
|
159
|
+
percent error on the index and gold products, 26 to 28 on crude, clustered
|
|
160
|
+
enough that independent-error statistics overstate your precision by an
|
|
161
|
+
order of magnitude. Do not use BVC where direction matters. And when you
|
|
162
|
+
build bars or buckets from classified signs, remember that the boundaries
|
|
163
|
+
themselves, not just the values inside them, are artifacts of the classifier
|
|
164
|
+
that signed them. The full story is in [docs/paper.md](docs/paper.md).
|