pretium 0.1.1__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 (99) hide show
  1. pretium-0.1.1/LICENSE-APACHE +202 -0
  2. pretium-0.1.1/LICENSE-MIT +21 -0
  3. pretium-0.1.1/NOTICE +6 -0
  4. pretium-0.1.1/PKG-INFO +208 -0
  5. pretium-0.1.1/README.md +172 -0
  6. pretium-0.1.1/pyproject.toml +74 -0
  7. pretium-0.1.1/python/pretium/__init__.py +672 -0
  8. pretium-0.1.1/python/pretium/_core.pyi +369 -0
  9. pretium-0.1.1/python/pretium/atlas.py +1335 -0
  10. pretium-0.1.1/python/pretium/baselines.py +517 -0
  11. pretium-0.1.1/python/pretium/checkpoint.py +298 -0
  12. pretium-0.1.1/python/pretium/edgar.py +853 -0
  13. pretium-0.1.1/python/pretium/envelope.py +643 -0
  14. pretium-0.1.1/python/pretium/facts.py +1113 -0
  15. pretium-0.1.1/python/pretium/gym.py +323 -0
  16. pretium-0.1.1/python/pretium/harness.py +609 -0
  17. pretium-0.1.1/python/pretium/loss.py +384 -0
  18. pretium-0.1.1/python/pretium/manifest.py +869 -0
  19. pretium-0.1.1/python/pretium/mcp.py +1484 -0
  20. pretium-0.1.1/python/pretium/portfolio.py +347 -0
  21. pretium-0.1.1/python/pretium/py.typed +0 -0
  22. pretium-0.1.1/python/pretium/ranking.py +496 -0
  23. pretium-0.1.1/python/pretium/replay.py +135 -0
  24. pretium-0.1.1/python/pretium/scenario.py +1031 -0
  25. pretium-0.1.1/python/pretium/spec.py +815 -0
  26. pretium-0.1.1/python/pretium/sweep.py +148 -0
  27. pretium-0.1.1/python/pretium/tca.py +417 -0
  28. pretium-0.1.1/python/pretium/universe_util.py +40 -0
  29. pretium-0.1.1/rust/Cargo.lock +1140 -0
  30. pretium-0.1.1/rust/Cargo.toml +94 -0
  31. pretium-0.1.1/rust/LICENSE-APACHE +202 -0
  32. pretium-0.1.1/rust/LICENSE-MIT +21 -0
  33. pretium-0.1.1/rust/NOTICE +6 -0
  34. pretium-0.1.1/rust/README.md +28 -0
  35. pretium-0.1.1/rust/examples/divergence.rs +487 -0
  36. pretium-0.1.1/rust/examples/divergence_multiday.rs +334 -0
  37. pretium-0.1.1/rust/examples/hazard_pow_probe.rs +78 -0
  38. pretium-0.1.1/rust/examples/libm_crate_probe.rs +23 -0
  39. pretium-0.1.1/rust/examples/libm_probe.rs +27 -0
  40. pretium-0.1.1/rust/examples/log_probe.rs +22 -0
  41. pretium-0.1.1/rust/examples/phi_probe.rs +28 -0
  42. pretium-0.1.1/rust/examples/s_phi_probe.rs +19 -0
  43. pretium-0.1.1/rust/examples/volume_floor_probe.rs +30 -0
  44. pretium-0.1.1/rust/src/economy/central_bank.rs +318 -0
  45. pretium-0.1.1/rust/src/economy/cycle.rs +159 -0
  46. pretium-0.1.1/rust/src/economy/daily.rs +745 -0
  47. pretium-0.1.1/rust/src/economy/invariants.rs +387 -0
  48. pretium-0.1.1/rust/src/economy/mod.rs +44 -0
  49. pretium-0.1.1/rust/src/economy/state.rs +507 -0
  50. pretium-0.1.1/rust/src/engine.rs +2629 -0
  51. pretium-0.1.1/rust/src/fair_value.rs +324 -0
  52. pretium-0.1.1/rust/src/lib.rs +80 -0
  53. pretium-0.1.1/rust/src/market/daily.rs +469 -0
  54. pretium-0.1.1/rust/src/market/factor_vol.rs +817 -0
  55. pretium-0.1.1/rust/src/market/factors.rs +891 -0
  56. pretium-0.1.1/rust/src/market/garch.rs +290 -0
  57. pretium-0.1.1/rust/src/market/hours.rs +217 -0
  58. pretium-0.1.1/rust/src/market/index_value.rs +201 -0
  59. pretium-0.1.1/rust/src/market/mod.rs +71 -0
  60. pretium-0.1.1/rust/src/market/tick.rs +940 -0
  61. pretium-0.1.1/rust/src/market_maker.rs +451 -0
  62. pretium-0.1.1/rust/src/mathx.rs +363 -0
  63. pretium-0.1.1/rust/src/microstructure.rs +891 -0
  64. pretium-0.1.1/rust/src/mispricing.rs +676 -0
  65. pretium-0.1.1/rust/src/order_book.rs +690 -0
  66. pretium-0.1.1/rust/src/params.rs +1303 -0
  67. pretium-0.1.1/rust/src/python.rs +555 -0
  68. pretium-0.1.1/rust/src/python_arrow.rs +649 -0
  69. pretium-0.1.1/rust/src/python_batch.rs +319 -0
  70. pretium-0.1.1/rust/src/python_book.rs +368 -0
  71. pretium-0.1.1/rust/src/python_engine.rs +2585 -0
  72. pretium-0.1.1/rust/src/python_log.rs +215 -0
  73. pretium-0.1.1/rust/src/python_params.rs +217 -0
  74. pretium-0.1.1/rust/src/rng.rs +769 -0
  75. pretium-0.1.1/rust/src/sectors.rs +173 -0
  76. pretium-0.1.1/rust/src/types.rs +19 -0
  77. pretium-0.1.1/rust/src/units.rs +147 -0
  78. pretium-0.1.1/rust/src/universe.rs +356 -0
  79. pretium-0.1.1/rust/src/wasm.rs +244 -0
  80. pretium-0.1.1/rust/sync-goldens.py +210 -0
  81. pretium-0.1.1/rust/tests/circuit_breaker.rs +377 -0
  82. pretium-0.1.1/rust/tests/divergence_statistics.rs +458 -0
  83. pretium-0.1.1/rust/tests/economy_parity.rs +872 -0
  84. pretium-0.1.1/rust/tests/fair_value_parity.rs +242 -0
  85. pretium-0.1.1/rust/tests/garch_regression.rs +204 -0
  86. pretium-0.1.1/rust/tests/market_daily_parity.rs +446 -0
  87. pretium-0.1.1/rust/tests/market_islands_parity.rs +355 -0
  88. pretium-0.1.1/rust/tests/market_maker_parity.rs +241 -0
  89. pretium-0.1.1/rust/tests/market_tick_parity.rs +541 -0
  90. pretium-0.1.1/rust/tests/mathx_parity.rs +364 -0
  91. pretium-0.1.1/rust/tests/microstructure_parity.rs +440 -0
  92. pretium-0.1.1/rust/tests/mispricing_parity.rs +897 -0
  93. pretium-0.1.1/rust/tests/order_book_parity.rs +336 -0
  94. pretium-0.1.1/rust/tests/prng_normals_full.rs +90 -0
  95. pretium-0.1.1/rust/tests/roster_mutation.rs +248 -0
  96. pretium-0.1.1/rust/tests/stream_alignment.rs +210 -0
  97. pretium-0.1.1/rust/tests/thirty_day_parity.rs +535 -0
  98. pretium-0.1.1/rust/tests/tick_regression.rs +371 -0
  99. pretium-0.1.1/rust/tests/ts_parity_smoke.rs +109 -0
@@ -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
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Simon Coombes
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.
pretium-0.1.1/NOTICE ADDED
@@ -0,0 +1,6 @@
1
+ pretium
2
+ Copyright 2026 Simon Coombes
3
+
4
+ This product includes software developed by Simon Coombes.
5
+ Licensed under the terms of either the MIT license (LICENSE-MIT) or the
6
+ Apache License, Version 2.0 (LICENSE-APACHE), at your option.
pretium-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: pretium
3
+ Version: 0.1.1
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Science/Research
6
+ Classifier: Intended Audience :: Financial and Insurance Industry
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Rust
9
+ Classifier: Topic :: Office/Business :: Financial :: Investment
10
+ Classifier: Topic :: Scientific/Engineering
11
+ Requires-Dist: pyarrow>=14 ; extra == 'arrow'
12
+ Requires-Dist: anthropic>=0.40 ; extra == 'claude'
13
+ Requires-Dist: pydantic>=2 ; extra == 'claude'
14
+ Requires-Dist: mcp>=2.0 ; extra == 'mcp'
15
+ Requires-Dist: numpy>=1.24 ; extra == 'rl'
16
+ Requires-Dist: gymnasium>=0.29 ; extra == 'rl'
17
+ Provides-Extra: arrow
18
+ Provides-Extra: claude
19
+ Provides-Extra: mcp
20
+ Provides-Extra: rl
21
+ License-File: LICENSE-APACHE
22
+ License-File: LICENSE-MIT
23
+ License-File: NOTICE
24
+ Summary: Deterministic market simulation with a real limit order book.
25
+ Keywords: simulation,finance,market,orderbook,deterministic,backtesting
26
+ Home-Page: https://simoncoombes.github.io/pretium
27
+ Author: Simon Coombes
28
+ License-Expression: MIT OR Apache-2.0
29
+ Requires-Python: >=3.11
30
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
31
+ Project-URL: Changelog, https://github.com/simoncoombes/pretium/releases
32
+ Project-URL: Documentation, https://simoncoombes.github.io/pretium
33
+ Project-URL: Homepage, https://simoncoombes.github.io/pretium
34
+ Project-URL: Repository, https://github.com/simoncoombes/pretium
35
+
36
+ # pretium
37
+
38
+ [![determinism](https://github.com/simoncoombes/pretium/actions/workflows/determinism.yml/badge.svg)](https://github.com/simoncoombes/pretium/actions/workflows/determinism.yml)
39
+ [![licence: MIT OR Apache-2.0](https://img.shields.io/badge/licence-MIT%20OR%20Apache--2.0-blue.svg)](#licence)
40
+ [![python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
41
+
42
+ A market simulator you can run a strategy against. Rust core, Python API.
43
+
44
+ Give it a seed and a set of companies and it runs a market forward: prices, a
45
+ limit order book, fills, and an economy that advances itself daily. Your
46
+ orders match against real depth, so trading moves the price the way it would
47
+ anywhere else.
48
+
49
+ It exists because historical data can't answer two questions. What would have
50
+ happened if I'd traded differently, and what actually caused this price move.
51
+
52
+ ## Install
53
+
54
+ ```
55
+ pip install pretium
56
+ ```
57
+
58
+ 0.1.1 is the current release, and 0.1.0 was the first. The API may still
59
+ move before 1.0, and anything that changes the simulated trajectory arrives
60
+ as a new model preset rather than an edit to an existing one, so a published
61
+ result stays reproducible.
62
+
63
+ ## In thirty seconds
64
+
65
+ ```python
66
+ import pretium as pt
67
+
68
+ universe = pt.Universe.random(40, seed=111)
69
+
70
+ spec = pt.StrategySpec.momentum(lookback_days=1.0, top_k=5)
71
+ scores = pt.evaluate({"mine": spec}, seed=7, universe=universe, days=10)
72
+
73
+ scores["mine"].return_pct # what it made
74
+ scores["mine"].impact_bps # what its own footprint cost
75
+ scores["mine"].strategy_fingerprint # sha256, cite this
76
+ ```
77
+
78
+ That's one market draw, which tells you as much about the seed as about the
79
+ strategy. `pt.rank` runs many seeds and compares them with a paired sign
80
+ test.
81
+
82
+ ## What makes it different
83
+
84
+ **Determinism that's checked.** The crate ships its own `exp`, `log`, `sin`
85
+ and `cos` instead of calling the platform libm. Every release builds five
86
+ targets, runs one fixed simulation inside each, and compares digests. A
87
+ disagreement fails the release. A WebAssembly build produces the same digest
88
+ as the native one.
89
+
90
+ **Ground truth you can read.** The simulator computed every price, so it can
91
+ tell you why. One row per instrument per tick, with seven factor
92
+ contributions that sum to the move and a residual around 1e-16. No historical
93
+ dataset carries those labels. You can see that a stock fell, never that 60%
94
+ of the fall was order-flow pressure.
95
+
96
+ **Counterfactuals you can run.** The same seed runs with and without your
97
+ orders, so every fill is priced against the market where you never traded.
98
+ That's the number TCA vendors approximate.
99
+
100
+ **Results someone else can check.** A `StrategySpec` is a declarative,
101
+ hashable document rather than an arbitrary callable. A `RunManifest` carries
102
+ the seed, universe, macro conditions, scenario, model and strategy together
103
+ with the expected digest. `reproduce()` refuses on a mismatch and names the
104
+ culprit, because a manifest that quietly reproduced a different market would
105
+ be worse than no manifest.
106
+
107
+ ## Driving it from an agent
108
+
109
+ ```
110
+ pip install "pretium[mcp]"
111
+ claude mcp add pretium -- pretium-mcp
112
+ ```
113
+
114
+ Eleven read-only tools over the simulator, so a coding agent can ask whether
115
+ a momentum strategy beats buy-and-hold here, and whether the difference is
116
+ real. Strategies, universes and scenarios are composed as data. There's no
117
+ path from a tool argument to code execution.
118
+
119
+ Every result carries computed caveats and full provenance. A model
120
+ summarising a result has the tool output and nothing else, and will otherwise
121
+ report `return_pct: 88.7` as "the strategy made 88.7%".
122
+ [The MCP server](https://simoncoombes.github.io/pretium/mcp.html) has the
123
+ tool list and the client configuration.
124
+
125
+ ## What it's bad at
126
+
127
+ **Good results here don't predict real returns.** The price process comes
128
+ from a known model, so a strategy that fits that model's structure will look
129
+ excellent and teach you nothing. A strategy that fails here is more
130
+ informative, because it broke against a live order book under honest impact
131
+ costs.
132
+
133
+ **Realism is a stated envelope, not a score.** `pt.facts.measure()` reports
134
+ ten statistics against real-market bands. At 252 days the shipped `pt-v3`
135
+ preset holds nine of the ten in band, and holds the same nine on axes the
136
+ calibration never saw: fresh seeds, and a fresh 60-name universe.
137
+
138
+ The tenth is the autocorrelation of volume changes, which misses by 13.7
139
+ seed-standard-deviations. It's excluded from the calibration objective
140
+ deliberately, because an optimiser pointed at an unreachable target doesn't
141
+ fail cleanly, it distorts every other parameter chasing it. In practice a
142
+ volume forecast here is never wrong twice running, so an execution algorithm
143
+ faces an easier scheduling problem than the one it was written for.
144
+
145
+ **Six gaps are measured and named rather than assumed.** The certified
146
+ horizon is 252 days and the model doesn't hold beyond it. Volatility memory
147
+ decays exponentially where real markets decay hyperbolically. Tails are too
148
+ thin over multi-year windows. Scenario response is directionally right but
149
+ not calibrated in magnitude. And certification was measured on a
150
+ sector-balanced roster, which no real index is.
151
+ [The realism envelope](https://simoncoombes.github.io/pretium/trust.html)
152
+ states each gap and what it forbids. `pt.envelope.check()` refuses to certify
153
+ a question that falls outside one.
154
+
155
+ **Single venue, no latency, no strategic counterparties.** Orders arrive
156
+ instantly, there's one book per name, and you trade against a market maker
157
+ and aggregate flow rather than agents that adapt to you.
158
+
159
+ ## Worked examples
160
+
161
+ Six notebooks and two scripts in [`examples/`](examples/), numbered in
162
+ reading order and executed as part of the test suite:
163
+
164
+ | | what it covers |
165
+ |---|---|
166
+ | [`01-first-simulation`](examples/01-first-simulation.ipynb) | Universe, engine, order book, determinism |
167
+ | [`02-evaluating-a-strategy`](examples/02-evaluating-a-strategy.ipynb) | Specs, baselines, ranking across seeds |
168
+ | [`03-why-did-the-price-move`](examples/03-why-did-the-price-move.ipynb) | The seven factors that sum to every move |
169
+ | [`04-how-realistic-is-this`](examples/04-how-realistic-is-this.ipynb) | The realism panel and the gaps |
170
+ | [`05-training-an-agent`](examples/05-training-an-agent.ipynb) | The Gymnasium environment, and what size costs |
171
+ | [`06-execution-and-impact`](examples/06-execution-and-impact.ipynb) | TCA and the counterfactual run |
172
+
173
+ Or a whole study in one file. Sweep, evaluation, TCA and replay in about five
174
+ seconds:
175
+
176
+ ```
177
+ python examples/07-research-workflow.py
178
+ ```
179
+
180
+ ## Documentation
181
+
182
+ Full docs: [**simoncoombes.github.io/pretium**](https://simoncoombes.github.io/pretium/)
183
+
184
+ Getting started and core concepts. Agents, evaluation and the RL environment.
185
+ Scenarios and macro paths, strategy specs, model presets, checkpointing and
186
+ forking, sharing a run, Arrow output and streaming sweeps, SEC EDGAR loading,
187
+ transaction cost analysis, the MCP server, running in the browser, the
188
+ realism envelope and metrics, and the conventions worth reading before you
189
+ hit them.
190
+
191
+ ## Contributing
192
+
193
+ See [CONTRIBUTING.md](CONTRIBUTING.md). One rule shapes the rest: a change to
194
+ the simulated trajectory is a breaking change, whatever its size. A market
195
+ that runs differently from the same seed invalidates every published result
196
+ that cited it.
197
+
198
+ ## Citing this
199
+
200
+ See [CITATION.cff](CITATION.cff), or cite a specific result by its manifest.
201
+ The seed, the universe fingerprint, the model fingerprint and the strategy
202
+ fingerprint together identify exactly what ran.
203
+
204
+ ## Licence
205
+
206
+ MIT OR Apache-2.0, at your option. See [LICENSE-MIT](LICENSE-MIT) and
207
+ [LICENSE-APACHE](LICENSE-APACHE).
208
+
@@ -0,0 +1,172 @@
1
+ # pretium
2
+
3
+ [![determinism](https://github.com/simoncoombes/pretium/actions/workflows/determinism.yml/badge.svg)](https://github.com/simoncoombes/pretium/actions/workflows/determinism.yml)
4
+ [![licence: MIT OR Apache-2.0](https://img.shields.io/badge/licence-MIT%20OR%20Apache--2.0-blue.svg)](#licence)
5
+ [![python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
6
+
7
+ A market simulator you can run a strategy against. Rust core, Python API.
8
+
9
+ Give it a seed and a set of companies and it runs a market forward: prices, a
10
+ limit order book, fills, and an economy that advances itself daily. Your
11
+ orders match against real depth, so trading moves the price the way it would
12
+ anywhere else.
13
+
14
+ It exists because historical data can't answer two questions. What would have
15
+ happened if I'd traded differently, and what actually caused this price move.
16
+
17
+ ## Install
18
+
19
+ ```
20
+ pip install pretium
21
+ ```
22
+
23
+ 0.1.1 is the current release, and 0.1.0 was the first. The API may still
24
+ move before 1.0, and anything that changes the simulated trajectory arrives
25
+ as a new model preset rather than an edit to an existing one, so a published
26
+ result stays reproducible.
27
+
28
+ ## In thirty seconds
29
+
30
+ ```python
31
+ import pretium as pt
32
+
33
+ universe = pt.Universe.random(40, seed=111)
34
+
35
+ spec = pt.StrategySpec.momentum(lookback_days=1.0, top_k=5)
36
+ scores = pt.evaluate({"mine": spec}, seed=7, universe=universe, days=10)
37
+
38
+ scores["mine"].return_pct # what it made
39
+ scores["mine"].impact_bps # what its own footprint cost
40
+ scores["mine"].strategy_fingerprint # sha256, cite this
41
+ ```
42
+
43
+ That's one market draw, which tells you as much about the seed as about the
44
+ strategy. `pt.rank` runs many seeds and compares them with a paired sign
45
+ test.
46
+
47
+ ## What makes it different
48
+
49
+ **Determinism that's checked.** The crate ships its own `exp`, `log`, `sin`
50
+ and `cos` instead of calling the platform libm. Every release builds five
51
+ targets, runs one fixed simulation inside each, and compares digests. A
52
+ disagreement fails the release. A WebAssembly build produces the same digest
53
+ as the native one.
54
+
55
+ **Ground truth you can read.** The simulator computed every price, so it can
56
+ tell you why. One row per instrument per tick, with seven factor
57
+ contributions that sum to the move and a residual around 1e-16. No historical
58
+ dataset carries those labels. You can see that a stock fell, never that 60%
59
+ of the fall was order-flow pressure.
60
+
61
+ **Counterfactuals you can run.** The same seed runs with and without your
62
+ orders, so every fill is priced against the market where you never traded.
63
+ That's the number TCA vendors approximate.
64
+
65
+ **Results someone else can check.** A `StrategySpec` is a declarative,
66
+ hashable document rather than an arbitrary callable. A `RunManifest` carries
67
+ the seed, universe, macro conditions, scenario, model and strategy together
68
+ with the expected digest. `reproduce()` refuses on a mismatch and names the
69
+ culprit, because a manifest that quietly reproduced a different market would
70
+ be worse than no manifest.
71
+
72
+ ## Driving it from an agent
73
+
74
+ ```
75
+ pip install "pretium[mcp]"
76
+ claude mcp add pretium -- pretium-mcp
77
+ ```
78
+
79
+ Eleven read-only tools over the simulator, so a coding agent can ask whether
80
+ a momentum strategy beats buy-and-hold here, and whether the difference is
81
+ real. Strategies, universes and scenarios are composed as data. There's no
82
+ path from a tool argument to code execution.
83
+
84
+ Every result carries computed caveats and full provenance. A model
85
+ summarising a result has the tool output and nothing else, and will otherwise
86
+ report `return_pct: 88.7` as "the strategy made 88.7%".
87
+ [The MCP server](https://simoncoombes.github.io/pretium/mcp.html) has the
88
+ tool list and the client configuration.
89
+
90
+ ## What it's bad at
91
+
92
+ **Good results here don't predict real returns.** The price process comes
93
+ from a known model, so a strategy that fits that model's structure will look
94
+ excellent and teach you nothing. A strategy that fails here is more
95
+ informative, because it broke against a live order book under honest impact
96
+ costs.
97
+
98
+ **Realism is a stated envelope, not a score.** `pt.facts.measure()` reports
99
+ ten statistics against real-market bands. At 252 days the shipped `pt-v3`
100
+ preset holds nine of the ten in band, and holds the same nine on axes the
101
+ calibration never saw: fresh seeds, and a fresh 60-name universe.
102
+
103
+ The tenth is the autocorrelation of volume changes, which misses by 13.7
104
+ seed-standard-deviations. It's excluded from the calibration objective
105
+ deliberately, because an optimiser pointed at an unreachable target doesn't
106
+ fail cleanly, it distorts every other parameter chasing it. In practice a
107
+ volume forecast here is never wrong twice running, so an execution algorithm
108
+ faces an easier scheduling problem than the one it was written for.
109
+
110
+ **Six gaps are measured and named rather than assumed.** The certified
111
+ horizon is 252 days and the model doesn't hold beyond it. Volatility memory
112
+ decays exponentially where real markets decay hyperbolically. Tails are too
113
+ thin over multi-year windows. Scenario response is directionally right but
114
+ not calibrated in magnitude. And certification was measured on a
115
+ sector-balanced roster, which no real index is.
116
+ [The realism envelope](https://simoncoombes.github.io/pretium/trust.html)
117
+ states each gap and what it forbids. `pt.envelope.check()` refuses to certify
118
+ a question that falls outside one.
119
+
120
+ **Single venue, no latency, no strategic counterparties.** Orders arrive
121
+ instantly, there's one book per name, and you trade against a market maker
122
+ and aggregate flow rather than agents that adapt to you.
123
+
124
+ ## Worked examples
125
+
126
+ Six notebooks and two scripts in [`examples/`](examples/), numbered in
127
+ reading order and executed as part of the test suite:
128
+
129
+ | | what it covers |
130
+ |---|---|
131
+ | [`01-first-simulation`](examples/01-first-simulation.ipynb) | Universe, engine, order book, determinism |
132
+ | [`02-evaluating-a-strategy`](examples/02-evaluating-a-strategy.ipynb) | Specs, baselines, ranking across seeds |
133
+ | [`03-why-did-the-price-move`](examples/03-why-did-the-price-move.ipynb) | The seven factors that sum to every move |
134
+ | [`04-how-realistic-is-this`](examples/04-how-realistic-is-this.ipynb) | The realism panel and the gaps |
135
+ | [`05-training-an-agent`](examples/05-training-an-agent.ipynb) | The Gymnasium environment, and what size costs |
136
+ | [`06-execution-and-impact`](examples/06-execution-and-impact.ipynb) | TCA and the counterfactual run |
137
+
138
+ Or a whole study in one file. Sweep, evaluation, TCA and replay in about five
139
+ seconds:
140
+
141
+ ```
142
+ python examples/07-research-workflow.py
143
+ ```
144
+
145
+ ## Documentation
146
+
147
+ Full docs: [**simoncoombes.github.io/pretium**](https://simoncoombes.github.io/pretium/)
148
+
149
+ Getting started and core concepts. Agents, evaluation and the RL environment.
150
+ Scenarios and macro paths, strategy specs, model presets, checkpointing and
151
+ forking, sharing a run, Arrow output and streaming sweeps, SEC EDGAR loading,
152
+ transaction cost analysis, the MCP server, running in the browser, the
153
+ realism envelope and metrics, and the conventions worth reading before you
154
+ hit them.
155
+
156
+ ## Contributing
157
+
158
+ See [CONTRIBUTING.md](CONTRIBUTING.md). One rule shapes the rest: a change to
159
+ the simulated trajectory is a breaking change, whatever its size. A market
160
+ that runs differently from the same seed invalidates every published result
161
+ that cited it.
162
+
163
+ ## Citing this
164
+
165
+ See [CITATION.cff](CITATION.cff), or cite a specific result by its manifest.
166
+ The seed, the universe fingerprint, the model fingerprint and the strategy
167
+ fingerprint together identify exactly what ran.
168
+
169
+ ## Licence
170
+
171
+ MIT OR Apache-2.0, at your option. See [LICENSE-MIT](LICENSE-MIT) and
172
+ [LICENSE-APACHE](LICENSE-APACHE).