clockbars 0.1.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.
- clockbars-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
- clockbars-0.1.0/.github/ISSUE_TEMPLATE/config.yml +1 -0
- clockbars-0.1.0/.github/ISSUE_TEMPLATE/feature_request.md +18 -0
- clockbars-0.1.0/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- clockbars-0.1.0/.github/dependabot.yml +12 -0
- clockbars-0.1.0/.github/workflows/ci.yml +43 -0
- clockbars-0.1.0/.github/workflows/release.yml +45 -0
- clockbars-0.1.0/.gitignore +31 -0
- clockbars-0.1.0/CHANGELOG.md +65 -0
- clockbars-0.1.0/CITATION.cff +24 -0
- clockbars-0.1.0/CONTRIBUTING.md +51 -0
- clockbars-0.1.0/LICENSE +21 -0
- clockbars-0.1.0/PKG-INFO +331 -0
- clockbars-0.1.0/README.md +296 -0
- clockbars-0.1.0/docs/hero.png +0 -0
- clockbars-0.1.0/docs/paper.md +331 -0
- clockbars-0.1.0/examples/make_hero.py +124 -0
- clockbars-0.1.0/pyproject.toml +73 -0
- clockbars-0.1.0/src/clockbars/__init__.py +31 -0
- clockbars-0.1.0/src/clockbars/builder.py +333 -0
- clockbars-0.1.0/src/clockbars/core.py +456 -0
- clockbars-0.1.0/src/clockbars/py.typed +1 -0
- clockbars-0.1.0/src/clockbars/synthetic.py +142 -0
- clockbars-0.1.0/tests/conftest.py +68 -0
- clockbars-0.1.0/tests/test_builder.py +261 -0
- clockbars-0.1.0/tests/test_pandas.py +62 -0
- clockbars-0.1.0/tests/test_sessions.py +195 -0
- clockbars-0.1.0/tests/test_synthetic.py +98 -0
- clockbars-0.1.0/tests/test_threshold_bars.py +243 -0
- clockbars-0.1.0/tests/test_time_bars.py +108 -0
- clockbars-0.1.0/tests/test_validation.py +220 -0
- clockbars-0.1.0/uv.lock +1469 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Output that looks wrong
|
|
4
|
+
labels: ["bug"]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**What happened**
|
|
8
|
+
|
|
9
|
+
**How to reproduce**
|
|
10
|
+
|
|
11
|
+
A snippet plus exact versions (`python`, `polars`, `clockbars`) is worth a
|
|
12
|
+
hundred words:
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
# minimal input that shows it
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**What you expected instead**
|
|
19
|
+
|
|
20
|
+
**Why you believe it is a bug**
|
|
21
|
+
|
|
22
|
+
If the output merely surprised you, say so. It may be working as documented,
|
|
23
|
+
and the documentation may be what needs fixing.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
blank_issues_enabled: false
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: A bar type, a convention change, or a quality-of-life improvement
|
|
4
|
+
labels: ["enhancement"]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**The problem you are trying to solve**
|
|
8
|
+
|
|
9
|
+
What does the current behavior cost you? A concrete example beats a general
|
|
10
|
+
description.
|
|
11
|
+
|
|
12
|
+
**What you would like instead**
|
|
13
|
+
|
|
14
|
+
**Alternatives you considered**
|
|
15
|
+
|
|
16
|
+
Imbalance and run bars are already on the roadmap — if this request is one
|
|
17
|
+
of those, say what your preferred thresholding behavior would be, since
|
|
18
|
+
that is where implementations differ.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## What changed
|
|
2
|
+
|
|
3
|
+
## Which invariant or documented convention does this touch
|
|
4
|
+
|
|
5
|
+
## Checklist
|
|
6
|
+
|
|
7
|
+
- [ ] `uv run ruff check .` passes
|
|
8
|
+
- [ ] `uv run mypy src` passes (strict)
|
|
9
|
+
- [ ] `uv run pytest -q --cov=clockbars` passes with coverage at 100%
|
|
10
|
+
- [ ] If a convention changed, the test that pins it changed in the same PR,
|
|
11
|
+
and the README / paper / CHANGELOG say so
|
|
@@ -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=clockbars
|
|
@@ -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) — no tokens 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=clockbars
|
|
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,31 @@
|
|
|
1
|
+
# Byte-compiled / caches
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
*.whl
|
|
9
|
+
|
|
10
|
+
# Environments
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
|
|
15
|
+
# Tooling
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
.ruff_cache/
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.coverage
|
|
20
|
+
htmlcov/
|
|
21
|
+
|
|
22
|
+
# Editors / OS
|
|
23
|
+
.vscode/
|
|
24
|
+
.idea/
|
|
25
|
+
.DS_Store
|
|
26
|
+
Thumbs.db
|
|
27
|
+
|
|
28
|
+
# Local data (never commit trade data)
|
|
29
|
+
*.parquet
|
|
30
|
+
*.csv
|
|
31
|
+
data/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Notable changes to clockbars are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
|
+
[SemVer](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] — 2026-11-27
|
|
8
|
+
|
|
9
|
+
First release.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `resample()` builds tick, volume, dollar, and time bars from a trade
|
|
14
|
+
stream, all returning one shared 13-column schema. Threshold bars accept
|
|
15
|
+
`session_starts`: accumulation restarts at each boundary, a bar never
|
|
16
|
+
straddles a rollover, and a trade exactly on a boundary belongs to the
|
|
17
|
+
new session.
|
|
18
|
+
- `BarBuilder` builds the same bars one trade at a time for live streams,
|
|
19
|
+
with `close_session()` as the streaming counterpart of `session_starts`
|
|
20
|
+
and `flush()` for the trailing bar. `bars_to_frame()` collects bars with
|
|
21
|
+
exactly `resample()`'s schema and dtypes.
|
|
22
|
+
- Restart-from-zero threshold rule: the crossing trade closes its bar, a
|
|
23
|
+
closed bar's total always meets the threshold, and only the final bar
|
|
24
|
+
of a segment can be partial — flagged, never dropped.
|
|
25
|
+
- Strict input validation: timezone-aware timestamps normalized to
|
|
26
|
+
`Datetime("ns", "UTC")`, sortedness required, and finiteness checked
|
|
27
|
+
separately from sign so NaN and inf cannot pass a sign check.
|
|
28
|
+
- Deterministic seeded trade generator (`synthetic_ticks`) with one
|
|
29
|
+
session per business day, U-shaped arrivals, size clustering at the
|
|
30
|
+
open and close, and volatility scaling with trade size.
|
|
31
|
+
- pandas input adapter, held to the same validation as Polars input.
|
|
32
|
+
- 171 tests: conservation, contiguity, threshold, partial-flag, OHLC and
|
|
33
|
+
VWAP consistency, determinism, validation, the pandas path, session
|
|
34
|
+
cuts, streaming parity with the batch path, and 200,000-trade scale runs.
|
|
35
|
+
- CI on Ubuntu and Windows across Python 3.11–3.14: ruff, strict mypy,
|
|
36
|
+
and pytest with statement coverage required at 100%.
|
|
37
|
+
- `py.typed` marker, so downstream type checkers see the package's types.
|
|
38
|
+
- `examples/make_hero.py` regenerates the README figure and its table
|
|
39
|
+
from a seed.
|
|
40
|
+
- `docs/paper.md`: short paper on why bar construction matters, its
|
|
41
|
+
literature, and the implementation errors the test suite pins.
|
|
42
|
+
- `CITATION.cff`, `CHANGELOG.md`, `CONTRIBUTING.md`, issue and PR
|
|
43
|
+
templates, and a dependabot schedule.
|
|
44
|
+
|
|
45
|
+
### Design decisions worth knowing before depending on this
|
|
46
|
+
|
|
47
|
+
- Overshoot is not carried into the next bar. A global cumulative sum
|
|
48
|
+
would dock the following bar for the previous bar's overshoot and close
|
|
49
|
+
it below threshold mid-series; `clockbars` restarts each bar at zero.
|
|
50
|
+
- Threshold comparisons use a `1e-9` relative tolerance, because summed
|
|
51
|
+
floats land on `499.9999999999999` and strict comparison would flag
|
|
52
|
+
phantom partial bars.
|
|
53
|
+
- A fractional tick threshold rounds up: 2.5 closes bars of 3 trades.
|
|
54
|
+
- Time-bar windows are half-open `[start, start + every)`, compound
|
|
55
|
+
intervals like `1h30m` are summed, and alignment is to the epoch, not
|
|
56
|
+
to the first trade.
|
|
57
|
+
- Batch and streaming must agree: exactly on bar boundaries, timestamps,
|
|
58
|
+
OHLC, counts, and partial flags; per-bar volume and notional to within
|
|
59
|
+
float-summation order (≤ 1e-12 relative), because a vectorised group sum
|
|
60
|
+
and a sequential accumulator sum the same floats in different orders.
|
|
61
|
+
- A trade exactly on a session boundary belongs to the new session, and a
|
|
62
|
+
session's final short bar is flagged partial rather than merged into
|
|
63
|
+
the next day.
|
|
64
|
+
|
|
65
|
+
[0.1.0]: https://github.com/zzionz/clockbars/releases/tag/v0.1.0
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use clockbars in your research, please cite it."
|
|
3
|
+
type: software
|
|
4
|
+
title: clockbars
|
|
5
|
+
authors:
|
|
6
|
+
- alias: zzionz
|
|
7
|
+
version: 0.1.0
|
|
8
|
+
date-released: "2026-11-27"
|
|
9
|
+
license: MIT
|
|
10
|
+
repository-code: "https://github.com/zzionz/clockbars"
|
|
11
|
+
abstract: >-
|
|
12
|
+
Information-driven bar construction for market data: tick, volume, dollar,
|
|
13
|
+
and time bars in Polars, built on one explicit restart-from-zero rule and
|
|
14
|
+
covered by an invariant test suite.
|
|
15
|
+
keywords:
|
|
16
|
+
- quantitative-finance
|
|
17
|
+
- market-microstructure
|
|
18
|
+
- financial-data
|
|
19
|
+
- polars
|
|
20
|
+
- order-flow
|
|
21
|
+
related-identifiers:
|
|
22
|
+
- type: url
|
|
23
|
+
value: "https://github.com/zzionz/clockbars/blob/main/docs/paper.md"
|
|
24
|
+
description: Accompanying paper
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Small library, short rules.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/zzionz/clockbars.git
|
|
9
|
+
cd clockbars
|
|
10
|
+
uv sync --all-extras
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The dev environment includes pandas and pyarrow so the pandas adapter is
|
|
14
|
+
tested in the same run as everything else.
|
|
15
|
+
|
|
16
|
+
## The gates
|
|
17
|
+
|
|
18
|
+
Every PR must pass all three, and CI enforces them:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
uv run ruff check .
|
|
22
|
+
uv run mypy src # strict
|
|
23
|
+
uv run pytest -q --cov=clockbars # coverage stays at 100%
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
100% statement coverage is enforced deliberately, at the current size of the
|
|
27
|
+
library (167 statements). If a line cannot be tested, the honest options are
|
|
28
|
+
to delete it or to argue for it in a PR — not to lower the threshold quietly.
|
|
29
|
+
|
|
30
|
+
## The one rule that matters
|
|
31
|
+
|
|
32
|
+
Conventions here are load-bearing. Whether overshoot leaks into the next bar,
|
|
33
|
+
how a partial final bar is flagged, what happens to naive timestamps — each
|
|
34
|
+
is documented in the README, stated in the paper, and pinned by a named test.
|
|
35
|
+
If you change one of these behaviors, the PR changes all three artifacts in
|
|
36
|
+
the same commit: the test that pins it, the README section that states it,
|
|
37
|
+
and the paper passage that explains why. A behavior change that arrives
|
|
38
|
+
without its documentation is a regression wearing a feature's clothes.
|
|
39
|
+
|
|
40
|
+
## Figures
|
|
41
|
+
|
|
42
|
+
`docs/hero.png` and every number in the README's comparison table come from
|
|
43
|
+
`examples/make_hero.py`. If you touch the generator or the engine, regenerate
|
|
44
|
+
both and commit the result, so the published numbers stay true.
|
|
45
|
+
|
|
46
|
+
## Reporting problems
|
|
47
|
+
|
|
48
|
+
Use the issue templates. For suspected wrong output, include the input, the
|
|
49
|
+
output, and the three versions (`python`, `polars`, `clockbars`) — and say
|
|
50
|
+
whether you believe it is a bug or an undocumented convention, since those
|
|
51
|
+
get very different fixes.
|
clockbars-0.1.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.
|