quantrail 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.
Files changed (59) hide show
  1. quantrail-0.1.0/.coderabbit.yaml +24 -0
  2. quantrail-0.1.0/.github/workflows/ci.yml +41 -0
  3. quantrail-0.1.0/.gitignore +23 -0
  4. quantrail-0.1.0/CHANGELOG.md +30 -0
  5. quantrail-0.1.0/CONTRIBUTING.md +33 -0
  6. quantrail-0.1.0/LICENSE +202 -0
  7. quantrail-0.1.0/NOTICE +6 -0
  8. quantrail-0.1.0/PKG-INFO +149 -0
  9. quantrail-0.1.0/README.md +129 -0
  10. quantrail-0.1.0/README.zh-TW.md +131 -0
  11. quantrail-0.1.0/assets/architecture.svg +112 -0
  12. quantrail-0.1.0/assets/brand/option-a-track.svg +15 -0
  13. quantrail-0.1.0/assets/brand/option-b-verified.svg +15 -0
  14. quantrail-0.1.0/assets/brand/option-c-q.svg +13 -0
  15. quantrail-0.1.0/assets/brand/quantrail-badge.svg +53 -0
  16. quantrail-0.1.0/assets/brand/quantrail-mark.svg +44 -0
  17. quantrail-0.1.0/assets/social-preview.png +0 -0
  18. quantrail-0.1.0/assets/trust-report.svg +28 -0
  19. quantrail-0.1.0/docs/adr/0001-scope-and-boundaries.md +20 -0
  20. quantrail-0.1.0/docs/adr/0002-unknown-provenance-is-a-value.md +21 -0
  21. quantrail-0.1.0/docs/adr/0003-market-agnostic-core.md +20 -0
  22. quantrail-0.1.0/docs/adr/0004-license-and-contributions.md +19 -0
  23. quantrail-0.1.0/docs/adr/0005-explicit-versions.md +17 -0
  24. quantrail-0.1.0/docs/architecture.md +127 -0
  25. quantrail-0.1.0/docs/brand.md +22 -0
  26. quantrail-0.1.0/docs/zh-TW/architecture.md +129 -0
  27. quantrail-0.1.0/pyproject.toml +52 -0
  28. quantrail-0.1.0/scripts/render_architecture.py +155 -0
  29. quantrail-0.1.0/scripts/render_logo.py +164 -0
  30. quantrail-0.1.0/scripts/render_readme_assets.py +69 -0
  31. quantrail-0.1.0/scripts/render_social.py +85 -0
  32. quantrail-0.1.0/src/quantrail/__init__.py +17 -0
  33. quantrail-0.1.0/src/quantrail/accounting/__init__.py +1 -0
  34. quantrail-0.1.0/src/quantrail/accounting/ledger.py +159 -0
  35. quantrail-0.1.0/src/quantrail/backtest.py +116 -0
  36. quantrail-0.1.0/src/quantrail/core.py +218 -0
  37. quantrail-0.1.0/src/quantrail/datasets.py +199 -0
  38. quantrail-0.1.0/src/quantrail/engine.py +202 -0
  39. quantrail-0.1.0/src/quantrail/markets/__init__.py +1 -0
  40. quantrail-0.1.0/src/quantrail/markets/generic.py +30 -0
  41. quantrail-0.1.0/src/quantrail/markets/tw_equity.py +105 -0
  42. quantrail-0.1.0/src/quantrail/research/__init__.py +1 -0
  43. quantrail-0.1.0/src/quantrail/research/trials.py +148 -0
  44. quantrail-0.1.0/src/quantrail/stats/__init__.py +1 -0
  45. quantrail-0.1.0/src/quantrail/stats/inference.py +143 -0
  46. quantrail-0.1.0/src/quantrail/stats/metrics.py +129 -0
  47. quantrail-0.1.0/tests/test_backtest_api.py +45 -0
  48. quantrail-0.1.0/tests/test_core.py +93 -0
  49. quantrail-0.1.0/tests/test_datasets.py +105 -0
  50. quantrail-0.1.0/tests/test_engine.py +121 -0
  51. quantrail-0.1.0/tests/test_inference.py +67 -0
  52. quantrail-0.1.0/tests/test_ledger.py +57 -0
  53. quantrail-0.1.0/tests/test_metrics.py +51 -0
  54. quantrail-0.1.0/tests/test_package.py +5 -0
  55. quantrail-0.1.0/tests/test_readme.py +20 -0
  56. quantrail-0.1.0/tests/test_reference_parity.py +43 -0
  57. quantrail-0.1.0/tests/test_trials.py +70 -0
  58. quantrail-0.1.0/tests/test_tw_equity.py +39 -0
  59. quantrail-0.1.0/uv.lock +439 -0
@@ -0,0 +1,24 @@
1
+ # CodeRabbit review settings. The GitHub app itself is installed by a maintainer.
2
+ language: en-US
3
+ reviews:
4
+ profile: assertive
5
+ request_changes_workflow: false
6
+ high_level_summary: true
7
+ path_instructions:
8
+ - path: "src/quantrail/**"
9
+ instructions: |
10
+ QuantRail values correctness over features. Flag:
11
+ - money or quantities computed with floats where Decimal is used elsewhere;
12
+ - any value invented when evidence is missing (it must refuse with a reason instead);
13
+ - market-specific constants in core, accounting or engine code (ADR 0003);
14
+ - silent handling of unknown provenance, price basis or availability (ADR 0002);
15
+ - implicit "latest" versions (ADR 0005);
16
+ - anything that could read data dated after a decision (look-ahead).
17
+ - path: "tests/**"
18
+ instructions: |
19
+ Expected values must be stated independently, not produced by the code under test.
20
+ Tests must not read market data or credentials; flag any committed data files.
21
+ - path: "docs/**"
22
+ instructions: |
23
+ English is the source of truth; translations under docs/zh-TW must not add or drop content.
24
+ Flag claims about features that the code does not implement yet.
@@ -0,0 +1,41 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ timeout-minutes: 10
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ python-version: ["3.11", "3.12", "3.13"]
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: astral-sh/setup-uv@v6
22
+ with:
23
+ python-version: ${{ matrix.python-version }}
24
+ - run: uv sync --locked
25
+ - run: uv run ruff check .
26
+ - run: uv run pytest
27
+
28
+ dco:
29
+ if: github.event_name == 'pull_request'
30
+ runs-on: ubuntu-latest
31
+ timeout-minutes: 5
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ with:
35
+ fetch-depth: 0
36
+ - name: Every commit is signed off
37
+ run: |
38
+ missing=$(git log --format='%H %(trailers:key=Signed-off-by,valueonly,separator=%x2C)' \
39
+ "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" \
40
+ | awk 'NF < 2 {print $1}')
41
+ if [ -n "$missing" ]; then echo "Commits without Signed-off-by:"; echo "$missing"; exit 1; fi
@@ -0,0 +1,23 @@
1
+ # Environments and caches
2
+ .venv/
3
+ __pycache__/
4
+ *.py[cod]
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .ipynb_checkpoints/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+
12
+ # Never commit data or local configuration
13
+ data/
14
+ runs/
15
+ *.parquet
16
+ *.feather
17
+ *.csv
18
+ !tests/fixtures/**/*.csv
19
+ .env
20
+ .env.*
21
+ !.env.example
22
+ local.toml
23
+ assets/social-preview.html
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to QuantRail are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/); before 1.0, a minor version may break the API.
6
+
7
+ ## [0.1.0] - 2026-10-06
8
+
9
+ First pre-release.
10
+
11
+ ### Added
12
+
13
+ - **Core types** (`quantrail.core`): `Provenance` and `Declaration` where `unknown` is an allowed, flagged value; `TrustFlag` and `TrustReport`; `Money` with `Decimal` amounts per currency; `Instrument` with quantity steps (shares, board lots, fractional crypto).
14
+ - **Data governance** (`quantrail.datasets`): versioned, hash-verified datasets loaded by explicit version only; `ingest()` for user tables (only a date and a close are required); `export_dataset()` refuses an unknown licence unless acknowledged.
15
+ - **Research discipline**: append-only trial registry with code fingerprints (`quantrail.research.trials`); metrics with fixed formulas and a BRAIN-style summary (`quantrail.stats.metrics`); paired circular block bootstrap, Holm correction, deflated Sharpe ratio and CSCV PBO (`quantrail.stats.inference`).
16
+ - **Accounting and simulation**: multi-currency ledger with settlement-dated cash (`quantrail.accounting.ledger`); next-open target-weight engine with `NO_FILL` reasons, no-trade band, buy-only dividend reinvestment and a daily NAV identity (`quantrail.engine`).
17
+ - **Markets**: Taiwan equities and ETFs (`quantrail.markets.tw_equity`) with T+2, commission with minimum fee and a sourced, effective-dated securities transaction tax rule; a generic proportional cost model (`quantrail.markets.generic`).
18
+ - **One-call API**: `quantrail.backtest()` on ingested data, with data-driven caveats merged into the trust report; refuses total-return prices combined with dividend events.
19
+ - **Verification**: the engine reproduces its private reference implementation to the cent (five runs, 1,953 sessions); `tests/test_reference_parity.py` reruns the comparison when pointed at your own copy of the data.
20
+ - **Documentation**: architecture (English and Traditional Chinese), ADRs 0001–0005, README quickstart executed by tests, generated logo, hero, animated architecture diagram and social preview.
21
+
22
+ ### Known limitations
23
+
24
+ - Daily price limits and stock dividends are not modelled ([#15](https://github.com/ting-hong-shieh/quantrail/issues/15)).
25
+ - `backtest()` handles one instrument and infers sessions from price dates ([#16](https://github.com/ting-hong-shieh/quantrail/issues/16)).
26
+ - The ledger does not yet track average cost or realised P&L.
27
+ - Dependencies pin `pandas<3` ([#7](https://github.com/ting-hong-shieh/quantrail/issues/7)).
28
+ - Not yet published on PyPI.
29
+
30
+ [0.1.0]: https://github.com/ting-hong-shieh/quantrail/releases/tag/v0.1.0
@@ -0,0 +1,33 @@
1
+ # Contributing to QuantRail
2
+
3
+ Thank you for helping. QuantRail values correctness over features: a smaller change with tests that prove the behaviour is better than a large one without.
4
+
5
+ ## Ground rules
6
+
7
+ 1. **No market data in the repository.** Tests use synthetic fixtures. Do not commit vendor or exchange data, even small samples.
8
+ 2. **No credentials.** API keys, tokens and account identifiers never belong in code, tests or examples.
9
+ 3. **Respect data source terms.** Adapters are accepted only for sources whose terms allow programmatic access; document those terms in the adapter.
10
+ 4. **Tests prove behaviour.** Accounting and statistics changes need tests with independently computed expected values, not values produced by the code under test.
11
+ 5. **Explain refusals.** When the code cannot support an action, it returns or raises a reason, never an invented value.
12
+
13
+ ## Developer Certificate of Origin
14
+
15
+ Every commit must be signed off, certifying the [Developer Certificate of Origin](https://developercertificate.org/):
16
+
17
+ ```bash
18
+ git commit -s -m "Describe the change"
19
+ ```
20
+
21
+ ## Development
22
+
23
+ ```bash
24
+ uv sync
25
+ uv run ruff check .
26
+ uv run pytest
27
+ ```
28
+
29
+ Pull requests run the same checks in CI. Keep pull requests focused on one change.
30
+
31
+ ## Language
32
+
33
+ Code, issues, pull requests and the English documentation are in English. Traditional Chinese translations live under `docs/zh-TW/` and in `README.zh-TW.md`; the English text is the source of truth.
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
quantrail-0.1.0/NOTICE ADDED
@@ -0,0 +1,6 @@
1
+ QuantRail
2
+ Copyright 2026 Ting-Hong Shieh
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+ QuantRail ships no market data. Data you load or fetch with QuantRail remains
6
+ subject to the terms of its original source.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.5
2
+ Name: quantrail
3
+ Version: 0.1.0
4
+ Summary: Quantitative research you can trust: data governance, ledger-accurate backtests and research discipline.
5
+ Project-URL: Repository, https://github.com/ting-hong-shieh/quantrail
6
+ Author: Ting-Hong Shieh
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Financial and Insurance Industry
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Office/Business :: Financial :: Investment
15
+ Requires-Python: >=3.11
16
+ Requires-Dist: numpy>=1.26
17
+ Requires-Dist: pandas<3,>=2.1
18
+ Requires-Dist: pyarrow<24,>=14
19
+ Description-Content-Type: text/markdown
20
+
21
+ <p align="center">
22
+ <img src="assets/brand/quantrail-badge.svg" width="104" alt="QuantRail logo">
23
+ </p>
24
+
25
+ <h1 align="center">QuantRail</h1>
26
+
27
+ <p align="center"><b>Every backtest lies a little. QuantRail tells you where.</b><br>
28
+ Data governance · ledger-accurate simulation · research discipline</p>
29
+
30
+ <p align="center">
31
+ <a href="https://github.com/ting-hong-shieh/quantrail/actions/workflows/ci.yml"><img src="https://github.com/ting-hong-shieh/quantrail/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
32
+ <img src="https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-3776AB?logo=python&logoColor=white" alt="Python 3.11 | 3.12 | 3.13">
33
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-0F766E" alt="Apache-2.0"></a>
34
+ <img src="https://img.shields.io/badge/status-pre--alpha-F59E0B" alt="Status: pre-alpha">
35
+ <a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
36
+ </p>
37
+
38
+ <p align="center">
39
+ <a href="README.zh-TW.md">繁體中文</a> ·
40
+ <a href="docs/architecture.md">Architecture</a> ·
41
+ <a href="docs/adr/">Decisions</a> ·
42
+ <a href="CONTRIBUTING.md">Contributing</a>
43
+ </p>
44
+
45
+ <p align="center">
46
+ <img src="assets/trust-report.svg" width="820" alt="A QuantRail result opens with a trust report listing everything it could not verify">
47
+ </p>
48
+
49
+ > **Status:** early development (v0.x); APIs will change. Nothing here is investment advice.
50
+
51
+ ## Why QuantRail?
52
+
53
+ Most backtests are easy to make look good and hard to trust:
54
+
55
+ - positions are multiplied by adjusted returns, so dividends, splits and settlement are approximated or double-counted;
56
+ - nobody records which data version, licence or availability time a result depended on;
57
+ - the many variants tried before the "winner" are forgotten, so overfitting goes unmeasured.
58
+
59
+ QuantRail is built around three pillars:
60
+
61
+ | Pillar | What you get |
62
+ | --- | --- |
63
+ | **Data governance** | Versioned, hashed datasets with manifests: source, licence, price basis, point-in-time availability, quality checks. "Unknown" is allowed and reported, never hidden. |
64
+ | **Ledger-accurate simulation** | Raw prices plus explicit events (fees, taxes, dividends, splits, settlement). Every day's change in wealth must reconcile. |
65
+ | **Research discipline** | Append-only trial registry, frozen experiment contracts, sealed holdout data, and built-in paired block bootstrap, Holm correction, deflated Sharpe ratio and probability of backtest overfitting. |
66
+
67
+ ## Quickstart
68
+
69
+ ```python
70
+ import tempfile
71
+
72
+ import numpy as np
73
+ import pandas as pd
74
+
75
+ import quantrail as qr
76
+ from quantrail.markets.generic import ProportionalCosts
77
+
78
+ # Any price table you have: only a date and a close are required.
79
+ days = pd.bdate_range("2024-01-01", periods=250)
80
+ returns = np.random.default_rng(0).normal(0.0004, 0.01, 250)
81
+ prices = pd.DataFrame({"date": days, "close": 100 * np.exp(np.cumsum(returns))})
82
+
83
+ store = tempfile.mkdtemp()
84
+ data = qr.ingest(prices, root=store, dataset_id="my-prices", version="v1", instrument="X:ABC")
85
+
86
+ asset = qr.Instrument("X:ABC", "X", "equity", "USD")
87
+ result = qr.backtest(data, instrument=asset, capital=10_000,
88
+ costs=ProportionalCosts(commission_rate="0.001"))
89
+ print(result.report())
90
+ ```
91
+
92
+ The report starts with what QuantRail could not verify, because nothing was declared:
93
+
94
+ ```text
95
+ Trust report:
96
+ [!] SOURCE_UNKNOWN: Data source is not recorded.
97
+ [!] LICENCE_UNKNOWN: Licence is unknown: private research only; ...
98
+ [!] PRICE_BASIS_UNKNOWN: Prices may be raw or adjusted; ...
99
+ [!] ACCOUNTING_APPROXIMATE: Ledger-accurate accounting needs raw prices plus dividend and split events.
100
+ [!] AVAILABILITY_UNVERIFIED: Availability time is not declared; ...
101
+ [!] NO_OPEN_PRICES: No open prices: next-open execution cannot be modelled.
102
+ [!] EXECUTION_NEXT_CLOSE_PROXY: No open prices: orders fill at the next session's close.
103
+ [i] CALENDAR_FROM_PRICES: Sessions are inferred from price dates; ...
104
+ ```
105
+
106
+ Declare provenance (`qr.Provenance`), price basis and availability (`qr.Declaration`), add open prices and corporate actions, and the caveats disappear one by one.
107
+
108
+ ## Verified to the cent
109
+
110
+ The engine and the Taiwan equity module were ported from a private research implementation and must reproduce it exactly. On eight years of a Taiwan ETF (1,953 sessions, 16 cash dividends, one 4-for-1 split and a trading suspension), QuantRail matches the daily net asset value of five reference runs with **zero difference**: buy-and-hold, and three rules that sell (87 sells with securities transaction tax, including runs with a no-trade band and with doubled slippage). Units, cash, receivables, payables, commission, tax and slippage all match.
111
+
112
+ That reference was itself checked independently: its buy-and-hold ledger was reconciled against a total-return index, with every difference explained by cash drag, costs and timing, and against a second data source. The data is not distributed; [`tests/test_reference_parity.py`](tests/test_reference_parity.py) reruns the comparison when you point it at your own copy.
113
+
114
+ ## Markets
115
+
116
+ | Module | Status | Covered | Not yet |
117
+ | --- | --- | --- | --- |
118
+ | `markets.tw_equity`: Taiwan equities and ETFs | Beta | T+2 settlement, commission with minimum fee, securities transaction tax as a sourced, effective-dated rule, cash dividends, splits, odd lots and board lots | Daily price limits, stock dividends ([#15](https://github.com/ting-hong-shieh/quantrail/issues/15)) |
119
+ | `markets.generic`: any market | Available | Proportional commission with minimum, sell tax | Market-specific rules |
120
+ | Crypto | Planned ([#5](https://github.com/ting-hong-shieh/quantrail/issues/5)) | | Spot, then perpetuals |
121
+
122
+ QuantRail **ships no market data**. You bring your own, or fetch it with your own credentials from sources whose terms allow it. There is no broker connectivity or live trading in this repository.
123
+
124
+ ## Architecture
125
+
126
+ <p align="center">
127
+ <img src="assets/architecture.svg" width="900" alt="Animated flow: your data passes through data governance and the engine into a result with a trust report; accounting and market modules light up as they support the engine, research and stats light up as they judge the result; core types underlie everything">
128
+ </p>
129
+
130
+ Read the [architecture](docs/architecture.md) and the [decision records](docs/adr/) for the reasoning.
131
+
132
+ ## Install
133
+
134
+ Not yet on PyPI. For development:
135
+
136
+ ```bash
137
+ git clone https://github.com/ting-hong-shieh/quantrail.git
138
+ cd quantrail
139
+ uv sync
140
+ uv run pytest
141
+ ```
142
+
143
+ ## Contributing
144
+
145
+ Correctness comes before features: accounting and statistics changes need tests with independently computed expectations. Every commit is signed off (DCO). See [CONTRIBUTING.md](CONTRIBUTING.md).
146
+
147
+ ## Licence
148
+
149
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE). Data you use with QuantRail remains subject to its own source's terms.
@@ -0,0 +1,129 @@
1
+ <p align="center">
2
+ <img src="assets/brand/quantrail-badge.svg" width="104" alt="QuantRail logo">
3
+ </p>
4
+
5
+ <h1 align="center">QuantRail</h1>
6
+
7
+ <p align="center"><b>Every backtest lies a little. QuantRail tells you where.</b><br>
8
+ Data governance · ledger-accurate simulation · research discipline</p>
9
+
10
+ <p align="center">
11
+ <a href="https://github.com/ting-hong-shieh/quantrail/actions/workflows/ci.yml"><img src="https://github.com/ting-hong-shieh/quantrail/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
12
+ <img src="https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-3776AB?logo=python&logoColor=white" alt="Python 3.11 | 3.12 | 3.13">
13
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-0F766E" alt="Apache-2.0"></a>
14
+ <img src="https://img.shields.io/badge/status-pre--alpha-F59E0B" alt="Status: pre-alpha">
15
+ <a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="README.zh-TW.md">繁體中文</a> ·
20
+ <a href="docs/architecture.md">Architecture</a> ·
21
+ <a href="docs/adr/">Decisions</a> ·
22
+ <a href="CONTRIBUTING.md">Contributing</a>
23
+ </p>
24
+
25
+ <p align="center">
26
+ <img src="assets/trust-report.svg" width="820" alt="A QuantRail result opens with a trust report listing everything it could not verify">
27
+ </p>
28
+
29
+ > **Status:** early development (v0.x); APIs will change. Nothing here is investment advice.
30
+
31
+ ## Why QuantRail?
32
+
33
+ Most backtests are easy to make look good and hard to trust:
34
+
35
+ - positions are multiplied by adjusted returns, so dividends, splits and settlement are approximated or double-counted;
36
+ - nobody records which data version, licence or availability time a result depended on;
37
+ - the many variants tried before the "winner" are forgotten, so overfitting goes unmeasured.
38
+
39
+ QuantRail is built around three pillars:
40
+
41
+ | Pillar | What you get |
42
+ | --- | --- |
43
+ | **Data governance** | Versioned, hashed datasets with manifests: source, licence, price basis, point-in-time availability, quality checks. "Unknown" is allowed and reported, never hidden. |
44
+ | **Ledger-accurate simulation** | Raw prices plus explicit events (fees, taxes, dividends, splits, settlement). Every day's change in wealth must reconcile. |
45
+ | **Research discipline** | Append-only trial registry, frozen experiment contracts, sealed holdout data, and built-in paired block bootstrap, Holm correction, deflated Sharpe ratio and probability of backtest overfitting. |
46
+
47
+ ## Quickstart
48
+
49
+ ```python
50
+ import tempfile
51
+
52
+ import numpy as np
53
+ import pandas as pd
54
+
55
+ import quantrail as qr
56
+ from quantrail.markets.generic import ProportionalCosts
57
+
58
+ # Any price table you have: only a date and a close are required.
59
+ days = pd.bdate_range("2024-01-01", periods=250)
60
+ returns = np.random.default_rng(0).normal(0.0004, 0.01, 250)
61
+ prices = pd.DataFrame({"date": days, "close": 100 * np.exp(np.cumsum(returns))})
62
+
63
+ store = tempfile.mkdtemp()
64
+ data = qr.ingest(prices, root=store, dataset_id="my-prices", version="v1", instrument="X:ABC")
65
+
66
+ asset = qr.Instrument("X:ABC", "X", "equity", "USD")
67
+ result = qr.backtest(data, instrument=asset, capital=10_000,
68
+ costs=ProportionalCosts(commission_rate="0.001"))
69
+ print(result.report())
70
+ ```
71
+
72
+ The report starts with what QuantRail could not verify, because nothing was declared:
73
+
74
+ ```text
75
+ Trust report:
76
+ [!] SOURCE_UNKNOWN: Data source is not recorded.
77
+ [!] LICENCE_UNKNOWN: Licence is unknown: private research only; ...
78
+ [!] PRICE_BASIS_UNKNOWN: Prices may be raw or adjusted; ...
79
+ [!] ACCOUNTING_APPROXIMATE: Ledger-accurate accounting needs raw prices plus dividend and split events.
80
+ [!] AVAILABILITY_UNVERIFIED: Availability time is not declared; ...
81
+ [!] NO_OPEN_PRICES: No open prices: next-open execution cannot be modelled.
82
+ [!] EXECUTION_NEXT_CLOSE_PROXY: No open prices: orders fill at the next session's close.
83
+ [i] CALENDAR_FROM_PRICES: Sessions are inferred from price dates; ...
84
+ ```
85
+
86
+ Declare provenance (`qr.Provenance`), price basis and availability (`qr.Declaration`), add open prices and corporate actions, and the caveats disappear one by one.
87
+
88
+ ## Verified to the cent
89
+
90
+ The engine and the Taiwan equity module were ported from a private research implementation and must reproduce it exactly. On eight years of a Taiwan ETF (1,953 sessions, 16 cash dividends, one 4-for-1 split and a trading suspension), QuantRail matches the daily net asset value of five reference runs with **zero difference**: buy-and-hold, and three rules that sell (87 sells with securities transaction tax, including runs with a no-trade band and with doubled slippage). Units, cash, receivables, payables, commission, tax and slippage all match.
91
+
92
+ That reference was itself checked independently: its buy-and-hold ledger was reconciled against a total-return index, with every difference explained by cash drag, costs and timing, and against a second data source. The data is not distributed; [`tests/test_reference_parity.py`](tests/test_reference_parity.py) reruns the comparison when you point it at your own copy.
93
+
94
+ ## Markets
95
+
96
+ | Module | Status | Covered | Not yet |
97
+ | --- | --- | --- | --- |
98
+ | `markets.tw_equity`: Taiwan equities and ETFs | Beta | T+2 settlement, commission with minimum fee, securities transaction tax as a sourced, effective-dated rule, cash dividends, splits, odd lots and board lots | Daily price limits, stock dividends ([#15](https://github.com/ting-hong-shieh/quantrail/issues/15)) |
99
+ | `markets.generic`: any market | Available | Proportional commission with minimum, sell tax | Market-specific rules |
100
+ | Crypto | Planned ([#5](https://github.com/ting-hong-shieh/quantrail/issues/5)) | | Spot, then perpetuals |
101
+
102
+ QuantRail **ships no market data**. You bring your own, or fetch it with your own credentials from sources whose terms allow it. There is no broker connectivity or live trading in this repository.
103
+
104
+ ## Architecture
105
+
106
+ <p align="center">
107
+ <img src="assets/architecture.svg" width="900" alt="Animated flow: your data passes through data governance and the engine into a result with a trust report; accounting and market modules light up as they support the engine, research and stats light up as they judge the result; core types underlie everything">
108
+ </p>
109
+
110
+ Read the [architecture](docs/architecture.md) and the [decision records](docs/adr/) for the reasoning.
111
+
112
+ ## Install
113
+
114
+ Not yet on PyPI. For development:
115
+
116
+ ```bash
117
+ git clone https://github.com/ting-hong-shieh/quantrail.git
118
+ cd quantrail
119
+ uv sync
120
+ uv run pytest
121
+ ```
122
+
123
+ ## Contributing
124
+
125
+ Correctness comes before features: accounting and statistics changes need tests with independently computed expectations. Every commit is signed off (DCO). See [CONTRIBUTING.md](CONTRIBUTING.md).
126
+
127
+ ## Licence
128
+
129
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE). Data you use with QuantRail remains subject to its own source's terms.