kamakuraquantlab-hase 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_hase-0.1.0/LICENSE.md +228 -0
- kamakuraquantlab_hase-0.1.0/PKG-INFO +158 -0
- kamakuraquantlab_hase-0.1.0/README.md +125 -0
- kamakuraquantlab_hase-0.1.0/pyproject.toml +67 -0
- kamakuraquantlab_hase-0.1.0/setup.cfg +4 -0
- kamakuraquantlab_hase-0.1.0/src/hase/__init__.py +3 -0
- kamakuraquantlab_hase-0.1.0/src/hase/cli.py +206 -0
- kamakuraquantlab_hase-0.1.0/src/hase/dataset.py +93 -0
- kamakuraquantlab_hase-0.1.0/src/hase/derive/__init__.py +64 -0
- kamakuraquantlab_hase-0.1.0/src/hase/derive/book_state.py +51 -0
- kamakuraquantlab_hase-0.1.0/src/hase/derive/market_price.py +136 -0
- kamakuraquantlab_hase-0.1.0/src/hase/derive/vol_spread.py +128 -0
- kamakuraquantlab_hase-0.1.0/src/hase/layout.py +123 -0
- kamakuraquantlab_hase-0.1.0/src/hase/plot/__init__.py +6 -0
- kamakuraquantlab_hase-0.1.0/src/hase/plot/order_book.py +58 -0
- kamakuraquantlab_hase-0.1.0/src/hase/plot/style.py +69 -0
- kamakuraquantlab_hase-0.1.0/src/hase/plot/trades.py +40 -0
- kamakuraquantlab_hase-0.1.0/src/hase/store.py +85 -0
- kamakuraquantlab_hase-0.1.0/src/kamakuraquantlab_hase.egg-info/PKG-INFO +158 -0
- kamakuraquantlab_hase-0.1.0/src/kamakuraquantlab_hase.egg-info/SOURCES.txt +24 -0
- kamakuraquantlab_hase-0.1.0/src/kamakuraquantlab_hase.egg-info/dependency_links.txt +1 -0
- kamakuraquantlab_hase-0.1.0/src/kamakuraquantlab_hase.egg-info/entry_points.txt +2 -0
- kamakuraquantlab_hase-0.1.0/src/kamakuraquantlab_hase.egg-info/requires.txt +8 -0
- kamakuraquantlab_hase-0.1.0/src/kamakuraquantlab_hase.egg-info/top_level.txt +1 -0
- kamakuraquantlab_hase-0.1.0/tests/test_derive.py +246 -0
- kamakuraquantlab_hase-0.1.0/tests/test_plots.py +96 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
Hase is licensed under the **Apache License, Version 2.0**.
|
|
4
|
+
|
|
5
|
+
Hase は **Apache License 2.0** のもとで公開しています。
|
|
6
|
+
|
|
7
|
+
Copyright 2026 Kamakura Quant Lab / 鎌倉クオンツラボ
|
|
8
|
+
|
|
9
|
+
## Why Apache 2.0 rather than MIT
|
|
10
|
+
|
|
11
|
+
Two clauses matter for a tool like this one, and MIT has neither.
|
|
12
|
+
|
|
13
|
+
**Section 6 withholds trademark rights explicitly.** Hase is published so a
|
|
14
|
+
buyer can read what it does with their purchase token before running it, which
|
|
15
|
+
only works if the name means something. The licence grants the code and not the
|
|
16
|
+
name.
|
|
17
|
+
|
|
18
|
+
**Section 4(b) requires a modified file to say it was modified.** A fork that
|
|
19
|
+
changes what this tool does with a credential has to declare it. That is worth
|
|
20
|
+
more here than the brevity MIT would buy.
|
|
21
|
+
|
|
22
|
+
Neither clause restricts ordinary use. Fork it, ship it, sell something built
|
|
23
|
+
on it; the terms below are the standard Apache 2.0 text.
|
|
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,158 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kamakuraquantlab-hase
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Kamakura Quant Lab analysis toolkit
|
|
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: Documentation, https://kamakuraquantlab.jp/support/
|
|
9
|
+
Project-URL: Source, https://github.com/kamakuraquantlab/Hase
|
|
10
|
+
Project-URL: The data, https://kamakuraquantlab.jp/data/
|
|
11
|
+
Keywords: cryptocurrency,market-data,order-book,japan,quantitative-finance
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
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: pyarrow>=15.0
|
|
26
|
+
Requires-Dist: pandas>=2.0
|
|
27
|
+
Requires-Dist: numpy
|
|
28
|
+
Requires-Dist: matplotlib>=3.8
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Hase
|
|
35
|
+
|
|
36
|
+
The **Kamakura Quant Lab** analysis toolkit. Reads the bronze data Komachi
|
|
37
|
+
downloads, derives the silver and gold datasets the articles are written on,
|
|
38
|
+
and draws it.
|
|
39
|
+
|
|
40
|
+
Named for the district where the Great Buddha sits. Komachi is where you get
|
|
41
|
+
things; Hase is where you go to look at them.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install kamakuraquantlab-hase
|
|
45
|
+
hase local --market COINCHECK:BTC_SPOT
|
|
46
|
+
hase derive MarketPrice --market COINCHECK:BTC_SPOT --start 2025-07-01 --end 2025-07-28
|
|
47
|
+
hase derive VolSpread --market COINCHECK:BTC_SPOT --start 2025-07-01 --end 2025-07-28
|
|
48
|
+
hase plot-trades --market COINCHECK:BTC_SPOT --date 2025-07-01 --output trades.png
|
|
49
|
+
hase plot-book --market COINCHECK:BTC_SPOT --date 2025-07-01 --output book.png
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## What it derives
|
|
53
|
+
|
|
54
|
+
Komachi downloads `bronze/`. Hase turns it into the datasets the articles are
|
|
55
|
+
written on, beside it under the same root, in the layout the warehouse uses.
|
|
56
|
+
|
|
57
|
+
| Dataset | Layer | What it is |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `BookState` | silver | Best bid and ask per snapshot, with mid, spread and the depth resting at the touch |
|
|
60
|
+
| `MarketPrice` | silver | What a given trade size would actually pay, by walking the book |
|
|
61
|
+
| `VolSpread` | gold | Mid and spread on a one-second grid, and realized volatility measured on it |
|
|
62
|
+
|
|
63
|
+
**Size is in base currency.** `--execution-size 0.002` is 0.002 BTC, and it is
|
|
64
|
+
the default because it means the same trade on every venue and on every day.
|
|
65
|
+
`--execution-notional 1000000` walks to a cash amount instead, which is a
|
|
66
|
+
different question and a different partition: ¥1,000,000 bought 0.0647 BTC in
|
|
67
|
+
July 2025 and 0.0796 BTC in September 2026, so a notional is not comparable
|
|
68
|
+
with itself over time, and a USDT-quoted book cannot be walked to a yen target
|
|
69
|
+
at all.
|
|
70
|
+
|
|
71
|
+
Deriving costs about a quarter of a second per market-day, so a market-year is
|
|
72
|
+
a minute and a half. `MarketPrice` is around an eighth the size of the bronze
|
|
73
|
+
it reads.
|
|
74
|
+
|
|
75
|
+
**Nothing is dropped silently.** A size the visible book cannot fill is `NaN`
|
|
76
|
+
with `filled` false, rather than a partial fill priced as a whole one. A
|
|
77
|
+
snapshot whose walked spread exceeds 100 bps is flagged `degenerate` rather
|
|
78
|
+
than removed: those are collector artefacts from a resync, they are present in
|
|
79
|
+
historical bronze, and how many of them a day holds is a fact about the archive
|
|
80
|
+
worth being able to count.
|
|
81
|
+
|
|
82
|
+
## Agreement with the pipeline that produced the data
|
|
83
|
+
|
|
84
|
+
Hase reimplements these derivations rather than importing them from the
|
|
85
|
+
pipeline that built the archive, because a tool you install must not depend on
|
|
86
|
+
trading code. That is only safe if the two agree, so the test suite checks
|
|
87
|
+
`MarketPrice` against the pipeline's own stored output where that warehouse is
|
|
88
|
+
mounted, and skips where it is not. Measured on a full day of
|
|
89
|
+
`COINCHECK:BTC_SPOT` and `GMO:BTC_JPY`, the largest relative difference is
|
|
90
|
+
4e-16 — floating-point last-bit, from accumulating the levels in a different
|
|
91
|
+
order.
|
|
92
|
+
|
|
93
|
+
## It holds no credential
|
|
94
|
+
|
|
95
|
+
Hase reads local files. It reaches no API, holds no token, and knows nothing
|
|
96
|
+
about entitlement or billing. That single rule is what lets one tool serve both
|
|
97
|
+
as a customer product and as an analysis environment for data you already have:
|
|
98
|
+
point it at a Komachi download or at your own warehouse, and it behaves the
|
|
99
|
+
same.
|
|
100
|
+
|
|
101
|
+
If a day is missing, Hase says so and tells you the `komachi` command that
|
|
102
|
+
would fetch it. It will not fetch anything itself.
|
|
103
|
+
|
|
104
|
+
## Where it reads from
|
|
105
|
+
|
|
106
|
+
`--root`, then `ROOT_PATH` or `KQL_ROOT_PATH` in the environment, then
|
|
107
|
+
`KQL_ROOT_PATH` in a `.env` in the working directory, then `~/kql-data`. The
|
|
108
|
+
`.env` is the one Komachi writes on first use, so the two tools agree without
|
|
109
|
+
being configured twice.
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
<root>/bronze/dataset=Trade/exchange=COINCHECK/symbol=BTC_SPOT/date=2025-07-01/data.parquet
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Dates are Tokyo days
|
|
116
|
+
|
|
117
|
+
A `date` partition holds the rows falling in `[00:00 JST, 24:00 JST)`, which is
|
|
118
|
+
`15:00` to `14:59` UTC. Timestamps inside the files are UTC epochs.
|
|
119
|
+
|
|
120
|
+
Plots are labelled in JST, matching the day they were cut in. This needs saying
|
|
121
|
+
because matplotlib converts datetimes to plain floats and forgets the zone: a
|
|
122
|
+
tz-aware series plots in the right place but is *labelled* in UTC unless the
|
|
123
|
+
formatter is told otherwise. A chart titled JST with a UTC axis is worse than
|
|
124
|
+
one with no timezone at all, so `plot/style.py` owns the zone and every axis
|
|
125
|
+
gets it explicitly.
|
|
126
|
+
|
|
127
|
+
## What the plots do
|
|
128
|
+
|
|
129
|
+
**`plot-trades`** — price across the day, with buy and sell volume beneath.
|
|
130
|
+
Volume is bucketed (`--bucket`, default `5min`) because a day is tens of
|
|
131
|
+
thousands of trades and a bar each is an unreadable smear. Buys and sells are
|
|
132
|
+
drawn apart rather than combined, since their balance is the reason to look.
|
|
133
|
+
|
|
134
|
+
**`plot-book`** — best bid and ask, with the spread beneath. Resampled to `1s`
|
|
135
|
+
by default: a day is around 230,000 snapshots, more points than the chart has
|
|
136
|
+
pixels. `--no-resample` keeps every one for a short window where the detail
|
|
137
|
+
matters. Resampling takes the last value in each interval rather than the mean,
|
|
138
|
+
because a mean of neighbouring quotes is a price that never existed and the
|
|
139
|
+
spread between two such means can come out negative.
|
|
140
|
+
|
|
141
|
+
The spread panel clips its view to the 99.5th percentile and labels how many
|
|
142
|
+
points fall above the cut. A few momentary wide spreads would otherwise set the
|
|
143
|
+
scale and flatten the rest of the day into a line, and hiding them silently
|
|
144
|
+
would be worse than saying how many there were.
|
|
145
|
+
|
|
146
|
+
## Not yet built
|
|
147
|
+
|
|
148
|
+
Silver and gold derivation, spread volatility, lead-lag, InfluxDB and Grafana
|
|
149
|
+
export. The lead-lag plot is the piece with no reference implementation.
|
|
150
|
+
|
|
151
|
+
## Tests
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
python -m pytest tests -q
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Fixtures write real parquet to a temporary directory. No network, no
|
|
158
|
+
credentials, no display.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Hase
|
|
2
|
+
|
|
3
|
+
The **Kamakura Quant Lab** analysis toolkit. Reads the bronze data Komachi
|
|
4
|
+
downloads, derives the silver and gold datasets the articles are written on,
|
|
5
|
+
and draws it.
|
|
6
|
+
|
|
7
|
+
Named for the district where the Great Buddha sits. Komachi is where you get
|
|
8
|
+
things; Hase is where you go to look at them.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install kamakuraquantlab-hase
|
|
12
|
+
hase local --market COINCHECK:BTC_SPOT
|
|
13
|
+
hase derive MarketPrice --market COINCHECK:BTC_SPOT --start 2025-07-01 --end 2025-07-28
|
|
14
|
+
hase derive VolSpread --market COINCHECK:BTC_SPOT --start 2025-07-01 --end 2025-07-28
|
|
15
|
+
hase plot-trades --market COINCHECK:BTC_SPOT --date 2025-07-01 --output trades.png
|
|
16
|
+
hase plot-book --market COINCHECK:BTC_SPOT --date 2025-07-01 --output book.png
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What it derives
|
|
20
|
+
|
|
21
|
+
Komachi downloads `bronze/`. Hase turns it into the datasets the articles are
|
|
22
|
+
written on, beside it under the same root, in the layout the warehouse uses.
|
|
23
|
+
|
|
24
|
+
| Dataset | Layer | What it is |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `BookState` | silver | Best bid and ask per snapshot, with mid, spread and the depth resting at the touch |
|
|
27
|
+
| `MarketPrice` | silver | What a given trade size would actually pay, by walking the book |
|
|
28
|
+
| `VolSpread` | gold | Mid and spread on a one-second grid, and realized volatility measured on it |
|
|
29
|
+
|
|
30
|
+
**Size is in base currency.** `--execution-size 0.002` is 0.002 BTC, and it is
|
|
31
|
+
the default because it means the same trade on every venue and on every day.
|
|
32
|
+
`--execution-notional 1000000` walks to a cash amount instead, which is a
|
|
33
|
+
different question and a different partition: ¥1,000,000 bought 0.0647 BTC in
|
|
34
|
+
July 2025 and 0.0796 BTC in September 2026, so a notional is not comparable
|
|
35
|
+
with itself over time, and a USDT-quoted book cannot be walked to a yen target
|
|
36
|
+
at all.
|
|
37
|
+
|
|
38
|
+
Deriving costs about a quarter of a second per market-day, so a market-year is
|
|
39
|
+
a minute and a half. `MarketPrice` is around an eighth the size of the bronze
|
|
40
|
+
it reads.
|
|
41
|
+
|
|
42
|
+
**Nothing is dropped silently.** A size the visible book cannot fill is `NaN`
|
|
43
|
+
with `filled` false, rather than a partial fill priced as a whole one. A
|
|
44
|
+
snapshot whose walked spread exceeds 100 bps is flagged `degenerate` rather
|
|
45
|
+
than removed: those are collector artefacts from a resync, they are present in
|
|
46
|
+
historical bronze, and how many of them a day holds is a fact about the archive
|
|
47
|
+
worth being able to count.
|
|
48
|
+
|
|
49
|
+
## Agreement with the pipeline that produced the data
|
|
50
|
+
|
|
51
|
+
Hase reimplements these derivations rather than importing them from the
|
|
52
|
+
pipeline that built the archive, because a tool you install must not depend on
|
|
53
|
+
trading code. That is only safe if the two agree, so the test suite checks
|
|
54
|
+
`MarketPrice` against the pipeline's own stored output where that warehouse is
|
|
55
|
+
mounted, and skips where it is not. Measured on a full day of
|
|
56
|
+
`COINCHECK:BTC_SPOT` and `GMO:BTC_JPY`, the largest relative difference is
|
|
57
|
+
4e-16 — floating-point last-bit, from accumulating the levels in a different
|
|
58
|
+
order.
|
|
59
|
+
|
|
60
|
+
## It holds no credential
|
|
61
|
+
|
|
62
|
+
Hase reads local files. It reaches no API, holds no token, and knows nothing
|
|
63
|
+
about entitlement or billing. That single rule is what lets one tool serve both
|
|
64
|
+
as a customer product and as an analysis environment for data you already have:
|
|
65
|
+
point it at a Komachi download or at your own warehouse, and it behaves the
|
|
66
|
+
same.
|
|
67
|
+
|
|
68
|
+
If a day is missing, Hase says so and tells you the `komachi` command that
|
|
69
|
+
would fetch it. It will not fetch anything itself.
|
|
70
|
+
|
|
71
|
+
## Where it reads from
|
|
72
|
+
|
|
73
|
+
`--root`, then `ROOT_PATH` or `KQL_ROOT_PATH` in the environment, then
|
|
74
|
+
`KQL_ROOT_PATH` in a `.env` in the working directory, then `~/kql-data`. The
|
|
75
|
+
`.env` is the one Komachi writes on first use, so the two tools agree without
|
|
76
|
+
being configured twice.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
<root>/bronze/dataset=Trade/exchange=COINCHECK/symbol=BTC_SPOT/date=2025-07-01/data.parquet
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Dates are Tokyo days
|
|
83
|
+
|
|
84
|
+
A `date` partition holds the rows falling in `[00:00 JST, 24:00 JST)`, which is
|
|
85
|
+
`15:00` to `14:59` UTC. Timestamps inside the files are UTC epochs.
|
|
86
|
+
|
|
87
|
+
Plots are labelled in JST, matching the day they were cut in. This needs saying
|
|
88
|
+
because matplotlib converts datetimes to plain floats and forgets the zone: a
|
|
89
|
+
tz-aware series plots in the right place but is *labelled* in UTC unless the
|
|
90
|
+
formatter is told otherwise. A chart titled JST with a UTC axis is worse than
|
|
91
|
+
one with no timezone at all, so `plot/style.py` owns the zone and every axis
|
|
92
|
+
gets it explicitly.
|
|
93
|
+
|
|
94
|
+
## What the plots do
|
|
95
|
+
|
|
96
|
+
**`plot-trades`** — price across the day, with buy and sell volume beneath.
|
|
97
|
+
Volume is bucketed (`--bucket`, default `5min`) because a day is tens of
|
|
98
|
+
thousands of trades and a bar each is an unreadable smear. Buys and sells are
|
|
99
|
+
drawn apart rather than combined, since their balance is the reason to look.
|
|
100
|
+
|
|
101
|
+
**`plot-book`** — best bid and ask, with the spread beneath. Resampled to `1s`
|
|
102
|
+
by default: a day is around 230,000 snapshots, more points than the chart has
|
|
103
|
+
pixels. `--no-resample` keeps every one for a short window where the detail
|
|
104
|
+
matters. Resampling takes the last value in each interval rather than the mean,
|
|
105
|
+
because a mean of neighbouring quotes is a price that never existed and the
|
|
106
|
+
spread between two such means can come out negative.
|
|
107
|
+
|
|
108
|
+
The spread panel clips its view to the 99.5th percentile and labels how many
|
|
109
|
+
points fall above the cut. A few momentary wide spreads would otherwise set the
|
|
110
|
+
scale and flatten the rest of the day into a line, and hiding them silently
|
|
111
|
+
would be worse than saying how many there were.
|
|
112
|
+
|
|
113
|
+
## Not yet built
|
|
114
|
+
|
|
115
|
+
Silver and gold derivation, spread volatility, lead-lag, InfluxDB and Grafana
|
|
116
|
+
export. The lead-lag plot is the piece with no reference implementation.
|
|
117
|
+
|
|
118
|
+
## Tests
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
python -m pytest tests -q
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Fixtures write real parquet to a temporary directory. No network, no
|
|
125
|
+
credentials, no display.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "kamakuraquantlab-hase"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Kamakura Quant Lab analysis toolkit"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
|
|
12
|
+
license = "Apache-2.0"
|
|
13
|
+
license-files = ["LICENSE.md"]
|
|
14
|
+
authors = [{name = "Kamakura Quant Lab", email = "support@kamakuraquantlab.jp"}]
|
|
15
|
+
keywords = ["cryptocurrency", "market-data", "order-book", "japan", "quantitative-finance"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
dependencies = [
|
|
30
|
+
"pyarrow>=15.0",
|
|
31
|
+
"pandas>=2.0",
|
|
32
|
+
"numpy",
|
|
33
|
+
"matplotlib>=3.8",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
dev = ["pytest>=7.0.0", "ruff>=0.1.0"]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://kamakuraquantlab.jp"
|
|
41
|
+
Documentation = "https://kamakuraquantlab.jp/support/"
|
|
42
|
+
Source = "https://github.com/kamakuraquantlab/Hase"
|
|
43
|
+
"The data" = "https://kamakuraquantlab.jp/data/"
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
# `hase.cli`, not a bare `cli`: a top-level module outside the package is
|
|
47
|
+
# not installed by `packages.find`, so the command imported whichever `cli`
|
|
48
|
+
# some other distribution happened to ship.
|
|
49
|
+
hase = "hase.cli:main"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools]
|
|
52
|
+
package-dir = {"" = "src"}
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.packages.find]
|
|
55
|
+
where = ["src"]
|
|
56
|
+
include = ["hase*"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 120
|
|
60
|
+
target-version = "py311"
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
extend-select = ["I"]
|
|
64
|
+
|
|
65
|
+
[tool.pytest.ini_options]
|
|
66
|
+
pythonpath = ["src"]
|
|
67
|
+
testpaths = ["tests"]
|