backtest-engine 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 (55) hide show
  1. backtest_engine-0.1.0/.gitattributes +6 -0
  2. backtest_engine-0.1.0/.github/workflows/ci.yml +119 -0
  3. backtest_engine-0.1.0/.gitignore +14 -0
  4. backtest_engine-0.1.0/Cargo.lock +270 -0
  5. backtest_engine-0.1.0/Cargo.toml +27 -0
  6. backtest_engine-0.1.0/LICENSE +21 -0
  7. backtest_engine-0.1.0/PKG-INFO +448 -0
  8. backtest_engine-0.1.0/README.md +426 -0
  9. backtest_engine-0.1.0/data/sample.csv +793 -0
  10. backtest_engine-0.1.0/data/spy_daily.csv +2515 -0
  11. backtest_engine-0.1.0/data/spy_daily.meta.json +14 -0
  12. backtest_engine-0.1.0/data/spy_daily.sha256 +1 -0
  13. backtest_engine-0.1.0/docs/benchmark.json +21 -0
  14. backtest_engine-0.1.0/docs/benchmark.md +43 -0
  15. backtest_engine-0.1.0/docs/case_study.html +146 -0
  16. backtest_engine-0.1.0/docs/case_study.sha256 +1 -0
  17. backtest_engine-0.1.0/docs/index.html +34 -0
  18. backtest_engine-0.1.0/examples/demo_lookahead.py +29 -0
  19. backtest_engine-0.1.0/examples/run_example.py +59 -0
  20. backtest_engine-0.1.0/pyproject.toml +50 -0
  21. backtest_engine-0.1.0/python/backtest_engine/__init__.py +73 -0
  22. backtest_engine-0.1.0/python/backtest_engine/__main__.py +6 -0
  23. backtest_engine-0.1.0/python/backtest_engine/_backtest_engine.pyi +223 -0
  24. backtest_engine-0.1.0/python/backtest_engine/cli.py +290 -0
  25. backtest_engine-0.1.0/python/backtest_engine/detector.py +204 -0
  26. backtest_engine-0.1.0/python/backtest_engine/py.typed +0 -0
  27. backtest_engine-0.1.0/python/backtest_engine/report.py +28 -0
  28. backtest_engine-0.1.0/python/backtest_engine/strategies.py +163 -0
  29. backtest_engine-0.1.0/python/backtest_engine/walkforward.py +163 -0
  30. backtest_engine-0.1.0/reports/example.html +254 -0
  31. backtest_engine-0.1.0/reports/expected.sha256 +1 -0
  32. backtest_engine-0.1.0/rust-toolchain.toml +4 -0
  33. backtest_engine-0.1.0/scripts/benchmark_real_data.py +180 -0
  34. backtest_engine-0.1.0/scripts/build_case_study.py +458 -0
  35. backtest_engine-0.1.0/scripts/fetch_real_data.py +166 -0
  36. backtest_engine-0.1.0/scripts/generate_data.py +188 -0
  37. backtest_engine-0.1.0/scripts/verify_case_study.py +42 -0
  38. backtest_engine-0.1.0/scripts/verify_report.py +47 -0
  39. backtest_engine-0.1.0/src/costs.rs +134 -0
  40. backtest_engine-0.1.0/src/engine.rs +798 -0
  41. backtest_engine-0.1.0/src/error.rs +44 -0
  42. backtest_engine-0.1.0/src/lib.rs +189 -0
  43. backtest_engine-0.1.0/src/metrics.rs +212 -0
  44. backtest_engine-0.1.0/src/queue.rs +132 -0
  45. backtest_engine-0.1.0/src/report.rs +401 -0
  46. backtest_engine-0.1.0/src/store.rs +587 -0
  47. backtest_engine-0.1.0/src/time.rs +155 -0
  48. backtest_engine-0.1.0/src/types.rs +500 -0
  49. backtest_engine-0.1.0/tests/__init__.py +1 -0
  50. backtest_engine-0.1.0/tests/helpers.py +24 -0
  51. backtest_engine-0.1.0/tests/test_detector.py +119 -0
  52. backtest_engine-0.1.0/tests/test_real_data.py +103 -0
  53. backtest_engine-0.1.0/tests/test_report.py +111 -0
  54. backtest_engine-0.1.0/tests/test_store.py +82 -0
  55. backtest_engine-0.1.0/tests/test_walkforward.py +87 -0
@@ -0,0 +1,6 @@
1
+ * text=auto eol=lf
2
+ reports/example.html -text
3
+ docs/case_study.html -text
4
+ *.pyd binary
5
+ *.so binary
6
+ *.dylib binary
@@ -0,0 +1,119 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ env:
12
+ CARGO_TERM_COLOR: always
13
+
14
+ jobs:
15
+ rust:
16
+ name: Rust core
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v7
20
+ - uses: actions/setup-python@v7
21
+ with:
22
+ python-version: "3.12"
23
+ - uses: dtolnay/rust-toolchain@stable
24
+ with:
25
+ components: rustfmt, clippy
26
+ - uses: Swatinem/rust-cache@v2
27
+ - name: Format
28
+ run: cargo fmt --all -- --check
29
+ - name: Clippy
30
+ run: cargo clippy --all-targets -- -D warnings
31
+ - name: Rust tests
32
+ run: cargo test --locked
33
+
34
+ python:
35
+ name: Python ${{ matrix.os }}
36
+ strategy:
37
+ fail-fast: false
38
+ matrix:
39
+ os: [ubuntu-latest, windows-latest, macos-latest]
40
+ runs-on: ${{ matrix.os }}
41
+ steps:
42
+ - uses: actions/checkout@v7
43
+ - uses: actions/setup-python@v7
44
+ with:
45
+ python-version: "3.12"
46
+ - uses: dtolnay/rust-toolchain@stable
47
+ - uses: Swatinem/rust-cache@v2
48
+ - name: Install tools
49
+ run: python -m pip install --upgrade pip pytest ruff mypy
50
+ - name: Build extension
51
+ run: python -m pip install .
52
+ - name: Tests
53
+ run: python -m pytest -q
54
+ - name: Lint
55
+ run: python -m ruff check python tests examples scripts
56
+ - name: Format check
57
+ run: python -m ruff format --check python tests examples scripts
58
+ - name: Type check
59
+ run: python -m mypy
60
+
61
+ report:
62
+ name: Reproducible report ${{ matrix.os }}
63
+ strategy:
64
+ fail-fast: false
65
+ matrix:
66
+ os: [ubuntu-latest, windows-latest, macos-latest]
67
+ runs-on: ${{ matrix.os }}
68
+ steps:
69
+ - uses: actions/checkout@v7
70
+ - uses: actions/setup-python@v7
71
+ with:
72
+ python-version: "3.12"
73
+ - uses: dtolnay/rust-toolchain@stable
74
+ - uses: Swatinem/rust-cache@v2
75
+ - name: Install tools
76
+ run: python -m pip install --upgrade pip
77
+ - name: Build extension
78
+ run: python -m pip install .
79
+ - name: Generate example report
80
+ run: python examples/run_example.py
81
+ - name: Verify committed report hash
82
+ run: python scripts/verify_report.py
83
+ - name: Prove the trap is detected
84
+ run: python -m backtest_engine check --strategy lookahead_trap --expect-detected
85
+ - name: Upload report
86
+ uses: actions/upload-artifact@v7
87
+ with:
88
+ name: report-${{ matrix.os }}
89
+ path: reports/example.html
90
+
91
+ case-study:
92
+ name: Real-data case study ${{ matrix.os }}
93
+ strategy:
94
+ fail-fast: false
95
+ matrix:
96
+ os: [ubuntu-latest, windows-latest]
97
+ runs-on: ${{ matrix.os }}
98
+ steps:
99
+ - uses: actions/checkout@v7
100
+ - uses: actions/setup-python@v7
101
+ with:
102
+ python-version: "3.12"
103
+ - uses: dtolnay/rust-toolchain@stable
104
+ - uses: Swatinem/rust-cache@v2
105
+ - name: Install tools
106
+ run: python -m pip install --upgrade pip
107
+ - name: Build extension
108
+ run: python -m pip install .
109
+ - name: Rebuild real-data report
110
+ run: python scripts/build_case_study.py
111
+ - name: Verify committed case study hash
112
+ run: python scripts/verify_case_study.py
113
+ - name: Prove the subtle leak is detected
114
+ run: python -m backtest_engine check --strategy full_sample_zscore --expect-detected
115
+ - name: Upload case study
116
+ uses: actions/upload-artifact@v7
117
+ with:
118
+ name: case-study-${{ matrix.os }}
119
+ path: docs/case_study.html
@@ -0,0 +1,14 @@
1
+ /target
2
+ /.venv
3
+ /dist
4
+ __pycache__/
5
+ *.py[cod]
6
+ *.pyd
7
+ *.pdb
8
+ *.so
9
+ *.dylib
10
+ *.egg-info/
11
+ .pytest_cache/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ .DS_Store
@@ -0,0 +1,270 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "backtest-engine"
7
+ version = "0.1.0"
8
+ dependencies = [
9
+ "csv",
10
+ "pyo3",
11
+ "sha2",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "block-buffer"
16
+ version = "0.10.4"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
19
+ dependencies = [
20
+ "generic-array",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "cfg-if"
25
+ version = "1.0.5"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
28
+
29
+ [[package]]
30
+ name = "cpufeatures"
31
+ version = "0.2.17"
32
+ source = "registry+https://github.com/rust-lang/crates.io-index"
33
+ checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
34
+ dependencies = [
35
+ "libc",
36
+ ]
37
+
38
+ [[package]]
39
+ name = "crypto-common"
40
+ version = "0.1.7"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
43
+ dependencies = [
44
+ "generic-array",
45
+ "typenum",
46
+ ]
47
+
48
+ [[package]]
49
+ name = "csv"
50
+ version = "1.4.0"
51
+ source = "registry+https://github.com/rust-lang/crates.io-index"
52
+ checksum = "52cd9d68cf7efc6ddfaaee42e7288d3a99d613d4b50f76ce9827ae0c6e14f938"
53
+ dependencies = [
54
+ "csv-core",
55
+ "itoa",
56
+ "ryu",
57
+ "serde_core",
58
+ ]
59
+
60
+ [[package]]
61
+ name = "csv-core"
62
+ version = "0.1.13"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "704a3c26996a80471189265814dbc2c257598b96b8a7feae2d31ace646bb9782"
65
+ dependencies = [
66
+ "memchr",
67
+ ]
68
+
69
+ [[package]]
70
+ name = "digest"
71
+ version = "0.10.7"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
74
+ dependencies = [
75
+ "block-buffer",
76
+ "crypto-common",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "generic-array"
81
+ version = "0.14.7"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
84
+ dependencies = [
85
+ "typenum",
86
+ "version_check",
87
+ ]
88
+
89
+ [[package]]
90
+ name = "heck"
91
+ version = "0.5.0"
92
+ source = "registry+https://github.com/rust-lang/crates.io-index"
93
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
94
+
95
+ [[package]]
96
+ name = "itoa"
97
+ version = "1.0.19"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
100
+
101
+ [[package]]
102
+ name = "libc"
103
+ version = "0.2.191"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
106
+
107
+ [[package]]
108
+ name = "memchr"
109
+ version = "2.8.3"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
112
+
113
+ [[package]]
114
+ name = "once_cell"
115
+ version = "1.21.4"
116
+ source = "registry+https://github.com/rust-lang/crates.io-index"
117
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
118
+
119
+ [[package]]
120
+ name = "portable-atomic"
121
+ version = "1.15.0"
122
+ source = "registry+https://github.com/rust-lang/crates.io-index"
123
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
124
+
125
+ [[package]]
126
+ name = "proc-macro2"
127
+ version = "1.0.107"
128
+ source = "registry+https://github.com/rust-lang/crates.io-index"
129
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
130
+ dependencies = [
131
+ "unicode-ident",
132
+ ]
133
+
134
+ [[package]]
135
+ name = "pyo3"
136
+ version = "0.30.1"
137
+ source = "registry+https://github.com/rust-lang/crates.io-index"
138
+ checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
139
+ dependencies = [
140
+ "libc",
141
+ "once_cell",
142
+ "portable-atomic",
143
+ "pyo3-build-config",
144
+ "pyo3-ffi",
145
+ "pyo3-macros",
146
+ ]
147
+
148
+ [[package]]
149
+ name = "pyo3-build-config"
150
+ version = "0.30.1"
151
+ source = "registry+https://github.com/rust-lang/crates.io-index"
152
+ checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
153
+ dependencies = [
154
+ "target-lexicon",
155
+ ]
156
+
157
+ [[package]]
158
+ name = "pyo3-ffi"
159
+ version = "0.30.1"
160
+ source = "registry+https://github.com/rust-lang/crates.io-index"
161
+ checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
162
+ dependencies = [
163
+ "libc",
164
+ "pyo3-build-config",
165
+ ]
166
+
167
+ [[package]]
168
+ name = "pyo3-macros"
169
+ version = "0.30.1"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
172
+ dependencies = [
173
+ "proc-macro2",
174
+ "pyo3-macros-backend",
175
+ "quote",
176
+ "syn",
177
+ ]
178
+
179
+ [[package]]
180
+ name = "pyo3-macros-backend"
181
+ version = "0.30.1"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
184
+ dependencies = [
185
+ "heck",
186
+ "proc-macro2",
187
+ "quote",
188
+ "syn",
189
+ ]
190
+
191
+ [[package]]
192
+ name = "quote"
193
+ version = "1.0.47"
194
+ source = "registry+https://github.com/rust-lang/crates.io-index"
195
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
196
+ dependencies = [
197
+ "proc-macro2",
198
+ ]
199
+
200
+ [[package]]
201
+ name = "ryu"
202
+ version = "1.0.23"
203
+ source = "registry+https://github.com/rust-lang/crates.io-index"
204
+ checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
205
+
206
+ [[package]]
207
+ name = "serde_core"
208
+ version = "1.0.229"
209
+ source = "registry+https://github.com/rust-lang/crates.io-index"
210
+ checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
211
+ dependencies = [
212
+ "serde_derive",
213
+ ]
214
+
215
+ [[package]]
216
+ name = "serde_derive"
217
+ version = "1.0.229"
218
+ source = "registry+https://github.com/rust-lang/crates.io-index"
219
+ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
220
+ dependencies = [
221
+ "proc-macro2",
222
+ "quote",
223
+ "syn",
224
+ ]
225
+
226
+ [[package]]
227
+ name = "sha2"
228
+ version = "0.10.9"
229
+ source = "registry+https://github.com/rust-lang/crates.io-index"
230
+ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
231
+ dependencies = [
232
+ "cfg-if",
233
+ "cpufeatures",
234
+ "digest",
235
+ ]
236
+
237
+ [[package]]
238
+ name = "syn"
239
+ version = "3.0.10"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
242
+ dependencies = [
243
+ "proc-macro2",
244
+ "quote",
245
+ "unicode-ident",
246
+ ]
247
+
248
+ [[package]]
249
+ name = "target-lexicon"
250
+ version = "0.13.6"
251
+ source = "registry+https://github.com/rust-lang/crates.io-index"
252
+ checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
253
+
254
+ [[package]]
255
+ name = "typenum"
256
+ version = "1.20.1"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
259
+
260
+ [[package]]
261
+ name = "unicode-ident"
262
+ version = "1.0.27"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
265
+
266
+ [[package]]
267
+ name = "version_check"
268
+ version = "0.9.5"
269
+ source = "registry+https://github.com/rust-lang/crates.io-index"
270
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
@@ -0,0 +1,27 @@
1
+ [package]
2
+ name = "backtest-engine"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+ rust-version = "1.85"
6
+ license = "MIT"
7
+ description = "Event-driven backtesting engine that proves the absence of look-ahead bias"
8
+ authors = ["Iker Abad"]
9
+ repository = "https://github.com/IkerAbad/backtest-engine"
10
+ readme = "README.md"
11
+
12
+ [lib]
13
+ name = "_backtest_engine"
14
+ crate-type = ["cdylib", "rlib"]
15
+
16
+ [dependencies]
17
+ pyo3 = { version = "0.30.1", features = ["abi3-py310"] }
18
+ csv = "1.3"
19
+ sha2 = "0.10"
20
+
21
+ [features]
22
+ default = []
23
+ extension-module = ["pyo3/extension-module"]
24
+
25
+ [profile.release]
26
+ lto = true
27
+ codegen-units = 1
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Iker Abad
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.