kamakuraquantlab-qate 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.
- kamakuraquantlab_qate-0.1.0/LICENSE.md +228 -0
- kamakuraquantlab_qate-0.1.0/PKG-INFO +306 -0
- kamakuraquantlab_qate-0.1.0/README.md +273 -0
- kamakuraquantlab_qate-0.1.0/pyproject.toml +74 -0
- kamakuraquantlab_qate-0.1.0/setup.cfg +4 -0
- kamakuraquantlab_qate-0.1.0/src/kamakuraquantlab_qate.egg-info/PKG-INFO +306 -0
- kamakuraquantlab_qate-0.1.0/src/kamakuraquantlab_qate.egg-info/SOURCES.txt +76 -0
- kamakuraquantlab_qate-0.1.0/src/kamakuraquantlab_qate.egg-info/dependency_links.txt +1 -0
- kamakuraquantlab_qate-0.1.0/src/kamakuraquantlab_qate.egg-info/requires.txt +8 -0
- kamakuraquantlab_qate-0.1.0/src/kamakuraquantlab_qate.egg-info/top_level.txt +1 -0
- kamakuraquantlab_qate-0.1.0/src/qate/__init__.py +0 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/__init__.py +0 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/api.py +27 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/conn.py +29 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/ev_loop.py +146 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/ev_q.py +9 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/ev_type.py +27 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/features.py +39 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/feed.py +94 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/gateway.py +33 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/model.py +353 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/order.py +232 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/order_api.py +24 -0
- kamakuraquantlab_qate-0.1.0/src/qate/core/symbol.py +80 -0
- kamakuraquantlab_qate-0.1.0/src/qate/exchange/__init__.py +31 -0
- kamakuraquantlab_qate-0.1.0/src/qate/exchange/factory.py +45 -0
- kamakuraquantlab_qate-0.1.0/src/qate/exchange/registry.py +118 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/__init__.py +43 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/corvus/__init__.py +15 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/corvus/config.py +85 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/corvus/v1.py +179 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/__init__.py +26 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/adjust_inventory.py +552 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/config.py +42 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/schedule.py +18 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/source.py +73 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/v1.py +405 -0
- kamakuraquantlab_qate-0.1.0/src/qate/strategy/pisces/v2.py +395 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/__init__.py +30 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/chart.py +363 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/config.py +13 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/exceptions.py +13 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/gateways/__init__.py +14 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/gateways/default.py +209 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/gateways/nonblocking.py +153 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/gateways/queued.py +40 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/gateways/simulator.py +167 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicator.py +24 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicators/__init__.py +7 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicators/atr.py +30 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicators/ema.py +28 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicators/macd.py +55 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicators/rsi.py +51 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/indicators/sma.py +17 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/inventory.py +172 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/metrics.py +137 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/param.py +85 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/pnl_tracker.py +333 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/replay.py +21 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/reporter.py +42 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/runtime.py +154 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/strategy.py +129 -0
- kamakuraquantlab_qate-0.1.0/src/qate/trading/trader.py +108 -0
- kamakuraquantlab_qate-0.1.0/src/qate/util/__init__.py +0 -0
- kamakuraquantlab_qate-0.1.0/src/qate/util/buffer.py +29 -0
- kamakuraquantlab_qate-0.1.0/src/qate/util/counter.py +59 -0
- kamakuraquantlab_qate-0.1.0/src/qate/util/dt_range.py +179 -0
- kamakuraquantlab_qate-0.1.0/src/qate/util/encoder.py +13 -0
- kamakuraquantlab_qate-0.1.0/tests/test_backtest_end_to_end.py +261 -0
- kamakuraquantlab_qate-0.1.0/tests/test_chart.py +193 -0
- kamakuraquantlab_qate-0.1.0/tests/test_example_strategies.py +177 -0
- kamakuraquantlab_qate-0.1.0/tests/test_exchange_registry.py +100 -0
- kamakuraquantlab_qate-0.1.0/tests/test_fee_rates.py +191 -0
- kamakuraquantlab_qate-0.1.0/tests/test_gateway_contract.py +110 -0
- kamakuraquantlab_qate-0.1.0/tests/test_initialisation.py +129 -0
- kamakuraquantlab_qate-0.1.0/tests/test_metrics.py +110 -0
- kamakuraquantlab_qate-0.1.0/tests/test_reporter.py +202 -0
- kamakuraquantlab_qate-0.1.0/tests/test_wire_format.py +137 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
qate is licensed under the **Apache License, Version 2.0**.
|
|
4
|
+
|
|
5
|
+
qate は **Apache License 2.0** のもとで公開しています。
|
|
6
|
+
|
|
7
|
+
Copyright 2026 Kamakura Quant Lab / 鎌倉クオンツラボ
|
|
8
|
+
|
|
9
|
+
## Why Apache 2.0 rather than MIT
|
|
10
|
+
|
|
11
|
+
The same two clauses that settled it for the other Kamakura Quant Lab packages,
|
|
12
|
+
and both matter more for a library than for a command-line tool.
|
|
13
|
+
|
|
14
|
+
**Section 6 withholds trademark rights explicitly.** qate is published as the
|
|
15
|
+
library a reader can check a backtest against, and it is published on the claim
|
|
16
|
+
that it cannot reach an exchange. That claim is attached to the name, so the
|
|
17
|
+
licence grants the code and not the name.
|
|
18
|
+
|
|
19
|
+
**Section 4(b) requires a modified file to say it was modified.** A fork that
|
|
20
|
+
adds live connectivity — which is precisely what has been kept out of this
|
|
21
|
+
package — has to declare the file it changed. That is worth more here than the
|
|
22
|
+
brevity MIT would buy.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Apache License
|
|
29
|
+
Version 2.0, January 2004
|
|
30
|
+
http://www.apache.org/licenses/
|
|
31
|
+
|
|
32
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
33
|
+
|
|
34
|
+
1. Definitions.
|
|
35
|
+
|
|
36
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
37
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
38
|
+
|
|
39
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
40
|
+
the copyright owner that is granting the License.
|
|
41
|
+
|
|
42
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
43
|
+
other entities that control, are controlled by, or are under common
|
|
44
|
+
control with that entity. For the purposes of this definition,
|
|
45
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
46
|
+
direction or management of such entity, whether by contract or
|
|
47
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
48
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
49
|
+
|
|
50
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
51
|
+
exercising permissions granted by this License.
|
|
52
|
+
|
|
53
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
54
|
+
including but not limited to software source code, documentation
|
|
55
|
+
source, and configuration files.
|
|
56
|
+
|
|
57
|
+
"Object" form shall mean any form resulting from mechanical
|
|
58
|
+
transformation or translation of a Source form, including but
|
|
59
|
+
not limited to compiled object code, generated documentation,
|
|
60
|
+
and conversions to other media types.
|
|
61
|
+
|
|
62
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
63
|
+
Object form, made available under the License, as indicated by a
|
|
64
|
+
copyright notice that is included in or attached to the work
|
|
65
|
+
(an example is provided in the Appendix below).
|
|
66
|
+
|
|
67
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
68
|
+
form, that is based on (or derived from) the Work and for which the
|
|
69
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
70
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
71
|
+
of this License, Derivative Works shall not include works that remain
|
|
72
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
73
|
+
the Work and Derivative Works thereof.
|
|
74
|
+
|
|
75
|
+
"Contribution" shall mean any work of authorship, including
|
|
76
|
+
the original version of the Work and any modifications or additions
|
|
77
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
78
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
79
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
80
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
81
|
+
means any form of electronic, verbal, or written communication sent
|
|
82
|
+
to the Licensor or its representatives, including but not limited to
|
|
83
|
+
communication on electronic mailing lists, source code control systems,
|
|
84
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
85
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
86
|
+
excluding communication that is conspicuously marked or otherwise
|
|
87
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
88
|
+
|
|
89
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
90
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
91
|
+
subsequently incorporated within the Work.
|
|
92
|
+
|
|
93
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
94
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
95
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
96
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
97
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
98
|
+
Work and such Derivative Works in Source or Object form.
|
|
99
|
+
|
|
100
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
101
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
102
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
103
|
+
(except as stated in this section) patent license to make, have made,
|
|
104
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
105
|
+
where such license applies only to those patent claims licensable
|
|
106
|
+
by such Contributor that are necessarily infringed by their
|
|
107
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
108
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
109
|
+
institute patent litigation against any entity (including a
|
|
110
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
111
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
112
|
+
or contributory patent infringement, then any patent licenses
|
|
113
|
+
granted to You under this License for that Work shall terminate
|
|
114
|
+
as of the date such litigation is filed.
|
|
115
|
+
|
|
116
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
117
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
118
|
+
modifications, and in Source or Object form, provided that You
|
|
119
|
+
meet the following conditions:
|
|
120
|
+
|
|
121
|
+
(a) You must give any other recipients of the Work or
|
|
122
|
+
Derivative Works a copy of this License; and
|
|
123
|
+
|
|
124
|
+
(b) You must cause any modified files to carry prominent notices
|
|
125
|
+
stating that You changed the files; and
|
|
126
|
+
|
|
127
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
128
|
+
that You distribute, all copyright, patent, trademark, and
|
|
129
|
+
attribution notices from the Source form of the Work,
|
|
130
|
+
excluding those notices that do not pertain to any part of
|
|
131
|
+
the Derivative Works; and
|
|
132
|
+
|
|
133
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
134
|
+
distribution, then any Derivative Works that You distribute must
|
|
135
|
+
include a readable copy of the attribution notices contained
|
|
136
|
+
within such NOTICE file, excluding those notices that do not
|
|
137
|
+
pertain to any part of the Derivative Works, in at least one
|
|
138
|
+
of the following places: within a NOTICE text file distributed
|
|
139
|
+
as part of the Derivative Works; within the Source form or
|
|
140
|
+
documentation, if provided along with the Derivative Works; or,
|
|
141
|
+
within a display generated by the Derivative Works, if and
|
|
142
|
+
wherever such third-party notices normally appear. The contents
|
|
143
|
+
of the NOTICE file are for informational purposes only and
|
|
144
|
+
do not modify the License. You may add Your own attribution
|
|
145
|
+
notices within Derivative Works that You distribute, alongside
|
|
146
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
147
|
+
that such additional attribution notices cannot be construed
|
|
148
|
+
as modifying the License.
|
|
149
|
+
|
|
150
|
+
You may add Your own copyright statement to Your modifications and
|
|
151
|
+
may provide additional or different license terms and conditions
|
|
152
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
153
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
154
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
155
|
+
the conditions stated in this License.
|
|
156
|
+
|
|
157
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
158
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
159
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
160
|
+
this License, without any additional terms or conditions.
|
|
161
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
162
|
+
the terms of any separate license agreement you may have executed
|
|
163
|
+
with Licensor regarding such Contributions.
|
|
164
|
+
|
|
165
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
166
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
167
|
+
except as required for reasonable and customary use in describing the
|
|
168
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
169
|
+
|
|
170
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
171
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
172
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
173
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
174
|
+
implied, including, without limitation, any warranties or conditions
|
|
175
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
176
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
177
|
+
appropriateness of using or redistributing the Work and assume any
|
|
178
|
+
risks associated with Your exercise of permissions under this License.
|
|
179
|
+
|
|
180
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
181
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
182
|
+
unless required by applicable law (such as deliberate and grossly
|
|
183
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
184
|
+
liable to You for damages, including any direct, indirect, special,
|
|
185
|
+
incidental, or consequential damages of any character arising as a
|
|
186
|
+
result of this License or out of the use or inability to use the
|
|
187
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
188
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
189
|
+
other commercial damages or losses), even if such Contributor
|
|
190
|
+
has been advised of the possibility of such damages.
|
|
191
|
+
|
|
192
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
193
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
194
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
195
|
+
or other liability obligations and/or rights consistent with this
|
|
196
|
+
License. However, in accepting such obligations, You may act only
|
|
197
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
198
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
199
|
+
defend, and hold each Contributor harmless for any liability
|
|
200
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
201
|
+
of your accepting any such warranty or additional liability.
|
|
202
|
+
|
|
203
|
+
END OF TERMS AND CONDITIONS
|
|
204
|
+
|
|
205
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
206
|
+
|
|
207
|
+
To apply the Apache License to your work, attach the following
|
|
208
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
209
|
+
replaced with your own identifying information. (Don't include
|
|
210
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
211
|
+
comment syntax for the file format. We also recommend that a
|
|
212
|
+
file or class name and description of purpose be included on the
|
|
213
|
+
same "printed page" as the copyright notice for easier
|
|
214
|
+
identification within third-party archives.
|
|
215
|
+
|
|
216
|
+
Copyright [yyyy] [name of copyright owner]
|
|
217
|
+
|
|
218
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
219
|
+
you may not use this file except in compliance with the License.
|
|
220
|
+
You may obtain a copy of the License at
|
|
221
|
+
|
|
222
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
223
|
+
|
|
224
|
+
Unless required by applicable law or agreed to in writing, software
|
|
225
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
226
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
227
|
+
See the License for the specific language governing permissions and
|
|
228
|
+
limitations under the License.
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kamakuraquantlab-qate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Quantitative trading library for backtesting against recorded market data
|
|
5
|
+
Author-email: Kamakura Quant Lab <support@kamakuraquantlab.jp>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://kamakuraquantlab.jp
|
|
8
|
+
Project-URL: Source, https://github.com/kamakuraquantlab/qate
|
|
9
|
+
Project-URL: The data, https://kamakuraquantlab.jp/data/
|
|
10
|
+
Keywords: backtesting,quantitative-finance,market-data,order-book,trading
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Operating System :: MacOS
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE.md
|
|
25
|
+
Requires-Dist: msgpack>=1.1
|
|
26
|
+
Requires-Dist: numpy>=2.0
|
|
27
|
+
Requires-Dist: pandas>=2.2
|
|
28
|
+
Requires-Dist: pyarrow>=15.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.1; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# qate
|
|
35
|
+
|
|
36
|
+
A quantitative trading library, built to be backtested. It provides the event
|
|
37
|
+
loop, order lifecycle, strategy base class, charts and indicators, inventory and
|
|
38
|
+
PnL tracking, and a simulator that fills orders against recorded order books.
|
|
39
|
+
|
|
40
|
+
It reaches no exchange. That is a property of the install, not a promise in a
|
|
41
|
+
README: there is no HTTP client and no WebSocket client anywhere in its dependency
|
|
42
|
+
tree, no venue endpoint in its source, and no request-signing or account code. A
|
|
43
|
+
venue arrives only as a separate package that registers an adapter, and without
|
|
44
|
+
one there is no code here that could connect anywhere.
|
|
45
|
+
|
|
46
|
+
It also does not know where market data lives, or what format it is in. That
|
|
47
|
+
belongs to whoever owns the data. `qate` defines what an order book and a trade
|
|
48
|
+
*are*; something else reads them and hands them over.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install kamakuraquantlab-qate
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For Kamakura Quant Lab data: [Komachi](https://github.com/kamakuraquantlab/Komachi)
|
|
55
|
+
downloads it, [Hase](https://github.com/kamakuraquantlab/Hase) derives features
|
|
56
|
+
from it, and [Enoshima](https://github.com/kamakuraquantlab/Enoshima) backtests
|
|
57
|
+
over it. This is the library Enoshima sits on.
|
|
58
|
+
|
|
59
|
+
It also has no notion of a deployment — no run directory, no host, no credential.
|
|
60
|
+
That is [qate-env](https://github.com/kamakuraquantlab/qate-env), which both
|
|
61
|
+
Enoshima and a live runner use to turn a directory of JSON into a run.
|
|
62
|
+
|
|
63
|
+
## Layout
|
|
64
|
+
|
|
65
|
+
| Package | Holds |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `qate.core` | Event loop, models, order lifecycle, and the interfaces a venue implements |
|
|
68
|
+
| `qate.trading` | Strategy base class and its config contract, gateways (live and simulated), the replay queue, bars and charts, indicators, inventory, PnL, the metric log, and the `Runtime` a live process runs in |
|
|
69
|
+
| `qate.strategy` | Two worked strategies, shipped to be read |
|
|
70
|
+
| `qate.exchange` | The adapter contract and registry. No venue lives here |
|
|
71
|
+
| `qate.util` | Date ranges, counters, encoding, replay-aware logging |
|
|
72
|
+
|
|
73
|
+
Run directories, credentials and the loader that reads them are not here; they are
|
|
74
|
+
`qate-env`. Nothing in this package names a path, a host or a key.
|
|
75
|
+
|
|
76
|
+
## Two worked strategies
|
|
77
|
+
|
|
78
|
+
An abstract base class is a poor teacher, so `qate` ships two complete strategies:
|
|
79
|
+
|
|
80
|
+
| Strategy | Is | Shows |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `qate.strategy.corvus` | Read a list of orders, place them, exit | The order lifecycle alone — place, reprice, cancel, fill, stop |
|
|
83
|
+
| `qate.strategy.pisces` | Cross-exchange arbitrage, maker one side and taker the other | A real idea, plus what startup, inventory and shutdown actually cost |
|
|
84
|
+
|
|
85
|
+
Read **corvus** first: it has no signal, no inventory and no schedule, so what is
|
|
86
|
+
left is the machinery every strategy needs and the part that is fiddly.
|
|
87
|
+
|
|
88
|
+
**pisces** is the same framework carrying a real trading idea, and its largest file
|
|
89
|
+
does no trading at all — it works out whether the strategy can start, because
|
|
90
|
+
exchanges have no sub-accounts and a strategy cannot assume the balance it left
|
|
91
|
+
behind. That ratio is the lesson, and it is what example strategies usually omit.
|
|
92
|
+
|
|
93
|
+
Neither is tuned and neither is a recommendation. Backtesting them needs nothing
|
|
94
|
+
but `qate`; trading them live needs an exchange adapter, which is a separate
|
|
95
|
+
install by design.
|
|
96
|
+
|
|
97
|
+
See [knowledge/05_corvus.md](knowledge/05_corvus.md) and
|
|
98
|
+
[knowledge/04_pisces.md](knowledge/04_pisces.md), and
|
|
99
|
+
[knowledge/03_writing_strategy.md](knowledge/03_writing_strategy.md) for the
|
|
100
|
+
`Variant` contract to write your own.
|
|
101
|
+
|
|
102
|
+
## Market data comes from outside
|
|
103
|
+
|
|
104
|
+
There is no reader here, deliberately. Reading recorded data means knowing a
|
|
105
|
+
storage layout, and a layout has an owner — for Kamakura Quant Lab data that is
|
|
106
|
+
`komachi`, which writes it. A trading library that also knew the layout would be a
|
|
107
|
+
second implementation of one question, and the day the two disagree is the day a
|
|
108
|
+
backtest silently skips a date the downloader thinks it has.
|
|
109
|
+
|
|
110
|
+
So a replayer hands `qate` events. `Enoshima` is the one that joins the two: it
|
|
111
|
+
asks `komachi` where the files are, reads them, and produces
|
|
112
|
+
`qate.core.model.OrderBook` and `Trade`. Anything that can produce those objects
|
|
113
|
+
works the same way.
|
|
114
|
+
|
|
115
|
+
`qate.util.dt_range.DtRange` is the shared vocabulary for *when*: it yields the ISO
|
|
116
|
+
date partition keys the bronze layer is laid out by, so a range maps onto files
|
|
117
|
+
with no conversion.
|
|
118
|
+
|
|
119
|
+
## Running a backtest
|
|
120
|
+
|
|
121
|
+
A replay is single-threaded on purpose: the events already exist, in order, and
|
|
122
|
+
two runs of the same data must give the same result. One queue in place of the
|
|
123
|
+
live ones collapses the threading into a single loop, so the same `Trader`,
|
|
124
|
+
`Strategy` and gateway code runs unchanged:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from qate.trading.gateways import SimulatorGateway
|
|
128
|
+
from qate.trading.replay import ReplayQueue
|
|
129
|
+
from qate.trading.trader import Trader
|
|
130
|
+
|
|
131
|
+
# events: an iterable of (EventType, OrderBook | Trade), in timestamp order.
|
|
132
|
+
# Where they come from is not qate's business — see above.
|
|
133
|
+
|
|
134
|
+
gateway = SimulatorGateway(ExchangeName.GMO, slippage_rate=0.0) # fills in place
|
|
135
|
+
|
|
136
|
+
trader = Trader(strategy, ReplayQueue(events)) # market data + own events
|
|
137
|
+
trader.add_gateway(gateway)
|
|
138
|
+
trader.register(EventType.MARKET_ORDER_BOOK, gateway.handle_order_book)
|
|
139
|
+
trader.run() # returns when the data ends
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Two behaviours are worth knowing before reading a result:
|
|
143
|
+
|
|
144
|
+
- **An order fills on the book after the one it was created on.** The simulator
|
|
145
|
+
matches against the next snapshot, never the one the strategy was looking at
|
|
146
|
+
when it decided. That is the latency model, and it is why a strategy cannot
|
|
147
|
+
trade on information it could not have had.
|
|
148
|
+
- **`Trader` runs a warmup pass first**, draining events into
|
|
149
|
+
`Strategy.warmup_*` until the strategy reports `is_ready`. Indicators get their
|
|
150
|
+
history before anything trades, and the warmup events are not traded on.
|
|
151
|
+
|
|
152
|
+
`tests/test_backtest_end_to_end.py` is this whole path in one file, from parquet
|
|
153
|
+
on disk to results on disk, and is the shortest complete example.
|
|
154
|
+
|
|
155
|
+
## Reporting a run as it happens
|
|
156
|
+
|
|
157
|
+
A `MetricLog` records everything for later; a `Reporter` is the other direction —
|
|
158
|
+
the few things a person wants to see while a strategy runs.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from qate.trading.reporter import Reporter
|
|
162
|
+
from qate.trading.runtime import Runtime
|
|
163
|
+
|
|
164
|
+
class Printer(Reporter):
|
|
165
|
+
def on_order(self, order_response):
|
|
166
|
+
print(order_response.summary)
|
|
167
|
+
|
|
168
|
+
runtime = Runtime(strategy) # the loop a live run sits in: conns, gateways, metrics
|
|
169
|
+
runtime.add_reporter(Printer())
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
One method per kind of outcome — `on_order`, `on_pnl_update`, `on_summary`,
|
|
173
|
+
`on_exception`, `on_message`, `on_start`, `on_stop` — and every one is a no-op by
|
|
174
|
+
default, so implement what you care about. Several reporters can be added and each
|
|
175
|
+
sees everything. A reporter that raises is logged and ignored: a run does not
|
|
176
|
+
depend on anyone being told.
|
|
177
|
+
|
|
178
|
+
No implementation ships here — a destination is a dependency, and a chat client in
|
|
179
|
+
this package would be one nobody backtesting asked for. A live runner adds its own.
|
|
180
|
+
|
|
181
|
+
## What a run records
|
|
182
|
+
|
|
183
|
+
A local, append-only log of metric records, and nothing else:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from qate.trading.metrics import MetricLog, RotationInterval
|
|
187
|
+
|
|
188
|
+
log = MetricLog(RotationInterval.FIVE_MINUTE, 256, "Metrics")
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
A running strategy appends to a file and never waits on a network; a finished run
|
|
192
|
+
is self-contained. Reading it back is `read_metrics_dir`.
|
|
193
|
+
|
|
194
|
+
Shipping that log anywhere — InfluxDB for charting, parquet for analysis — is a
|
|
195
|
+
later and separate step belonging to whoever wants it. `qate` has no storage layer
|
|
196
|
+
and no database client, which is why a run cannot fail because a backend is down.
|
|
197
|
+
Enoshima is the worked example of the other half.
|
|
198
|
+
|
|
199
|
+
## Supplying an exchange
|
|
200
|
+
|
|
201
|
+
Live trading needs an adapter package. It declares an entry point and registers
|
|
202
|
+
one `ExchangeAdapter` per venue:
|
|
203
|
+
|
|
204
|
+
```toml
|
|
205
|
+
[project.entry-points."qate.exchanges"]
|
|
206
|
+
my_venues = "my_venues:register"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from qate.core.model import ExchangeName
|
|
211
|
+
from qate.exchange import ExchangeAdapter, register
|
|
212
|
+
|
|
213
|
+
def register_all():
|
|
214
|
+
register(ExchangeAdapter(
|
|
215
|
+
exchange_name=ExchangeName.GMO,
|
|
216
|
+
create_api=GMOApi,
|
|
217
|
+
create_gateway=GMOGateway,
|
|
218
|
+
create_public_connection=GMOPublicConn,
|
|
219
|
+
create_private_connection=GMOPrivateConn,
|
|
220
|
+
))
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Every hook is optional, and a venue is resolved lazily on first use. Asking for
|
|
224
|
+
one that is not installed raises `UnknownExchange` naming what is; asking an
|
|
225
|
+
adapter for something it does not provide raises
|
|
226
|
+
`UnsupportedExchangeCapability` naming the hook. Set `QATE_EXCHANGE_PLUGINS` to
|
|
227
|
+
load an adapter from a checkout that is not installed.
|
|
228
|
+
|
|
229
|
+
### What a fill costs
|
|
230
|
+
|
|
231
|
+
An adapter carries what its venues charge, alongside the hooks — a fee schedule is
|
|
232
|
+
venue knowledge in exactly the way an endpoint is, and `qate` ships the shape of a rate
|
|
233
|
+
and no rate:
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
register(ExchangeAdapter(
|
|
237
|
+
exchange_name=ExchangeName.GMO,
|
|
238
|
+
create_api=GMOApi,
|
|
239
|
+
...
|
|
240
|
+
fee_rates={Symbol.BTC_SPOT: FeeSchedule(maker=-0.0001, taker=0.0005)},
|
|
241
|
+
))
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Fractions of notional, and **a negative maker rate is a rebate** — the fee comes back
|
|
245
|
+
negative and a `PnlUpdate` that subtracts it is correct.
|
|
246
|
+
|
|
247
|
+
`factory.get_fee_rate(market)` is how a run asks, and it is the one call in `factory`
|
|
248
|
+
that builds nothing: it reads a number off an adapter, so a replay may use it. A
|
|
249
|
+
`PnlTracker` resolves a rate per market, once, at setup:
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
tracker = PnlTracker()
|
|
253
|
+
tracker.register_fee(maker_market) # bitbank, say
|
|
254
|
+
tracker.register_fee(taker_market) # and GMO
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
One tracker covers several markets deliberately — pisces shares one between a maker
|
|
258
|
+
venue and a taker venue, which is what makes its round-trip PnL a round trip — so the
|
|
259
|
+
rate is per market and a fill is costed with the rate of the market it happened on. An
|
|
260
|
+
`Inventory` registers its own market, so a strategy built the usual way needs none of
|
|
261
|
+
this.
|
|
262
|
+
|
|
263
|
+
A market no rate was found for is costed at **zero**, with one warning: a venue whose
|
|
264
|
+
fees a run does not know is a configuration gap, not a reason to kill a live strategy
|
|
265
|
+
mid-position. It does mean a run with no adapter installed reports no fees at all,
|
|
266
|
+
which flatters any strategy whose edge is thinner than its costs. Rates were hardcoded
|
|
267
|
+
here once, and the price of their being right is that the package that speaks to a
|
|
268
|
+
venue is the one that has to say.
|
|
269
|
+
|
|
270
|
+
## Settings
|
|
271
|
+
|
|
272
|
+
There are none. `qate` reads no configuration file, consults no environment
|
|
273
|
+
variable, and holds no default path — a `Strategy` is handed its config object and
|
|
274
|
+
its params dict by whatever constructed it, and that is the whole of it.
|
|
275
|
+
|
|
276
|
+
Run directories, credential files and the loader that turns them into those objects
|
|
277
|
+
are [qate-env](https://github.com/kamakuraquantlab/qate-env). A backtest therefore
|
|
278
|
+
asks for no credential because there is nothing here that could ask: an
|
|
279
|
+
unauthenticated fallback is not a thing this package can express.
|
|
280
|
+
|
|
281
|
+
There is no market-data setting either. `qate` does not read market data, so it has
|
|
282
|
+
no opinion about where it is.
|
|
283
|
+
|
|
284
|
+
## Documentation
|
|
285
|
+
|
|
286
|
+
| Document | Read it when |
|
|
287
|
+
|---|---|
|
|
288
|
+
| [knowledge/01_philosophy.md](knowledge/01_philosophy.md) | Deciding whether to add a check, a test, or a comment |
|
|
289
|
+
| [knowledge/03_writing_strategy.md](knowledge/03_writing_strategy.md) | Writing a strategy: the `Variant` contract, config vs params |
|
|
290
|
+
| [knowledge/04_pisces.md](knowledge/04_pisces.md) | Cross-exchange arbitrage: startup, rebalance, shutdown |
|
|
291
|
+
| [knowledge/05_corvus.md](knowledge/05_corvus.md) | Single-shot order execution — the order lifecycle alone |
|
|
292
|
+
|
|
293
|
+
Environments — the directory, the lock, config discovery — are
|
|
294
|
+
[qate-env's knowledge/01_env.md](https://github.com/kamakuraquantlab/qate-env/blob/main/knowledge/01_env.md).
|
|
295
|
+
They were `knowledge/02_env.md` here, which is why the numbering skips.
|
|
296
|
+
|
|
297
|
+
## Development
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
pip install -e '.[dev]'
|
|
301
|
+
pytest
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Licence
|
|
305
|
+
|
|
306
|
+
Apache 2.0. See [LICENSE.md](LICENSE.md).
|