Hase
The Kamakura Quant Lab analysis toolkit. Reads the bronze data Komachi downloads, derives the silver and gold datasets the articles are written on, and draws it.
Named for the district where the Great Buddha sits. Komachi is where you get things; Hase is where you go to look at them.
pip install kamakuraquantlab-hase
hase local --market COINCHECK:BTC_SPOT
hase derive MarketPrice --market COINCHECK:BTC_SPOT --start 2025-07-01 --end 2025-07-28
hase derive VolSpread --market COINCHECK:BTC_SPOT --start 2025-07-01 --end 2025-07-28
hase derive VolSpread --market GMO:BTC_JPY --execution-size 0.002 --start 2026-06-01 --end 2026-06-30 \
--params 60:300:120 --params 60:900:300
hase plot-trades --market COINCHECK:BTC_SPOT --date 2025-07-01 --output trades.png
hase plot-book --market COINCHECK:BTC_SPOT --date 2025-07-01 --output book.png
What it derives
Komachi downloads bronze/. Hase turns it into the datasets the articles are
written on, beside it under the same root, in the layout the warehouse uses.
| Dataset | Layer | What it is |
|---|---|---|
BookState |
silver | Best bid and ask per snapshot, with mid, spread and the depth resting at the touch |
MarketPrice |
silver | What a given trade size would actually pay, by walking the book |
VolSpread |
gold | Bid, ask, mid and spread on a regular grid, and the volatility measured on it |
Size is in base currency. --execution-size 0.002 is 0.002 BTC, and it is
the default because it means the same trade on every venue and on every day.
--execution-notional 1000000 walks to a cash amount instead, which is a
different question and a different partition: ¥1,000,000 bought 0.0647 BTC in
July 2025 and 0.0796 BTC in September 2026, so a notional is not comparable
with itself over time, and a USDT-quoted book cannot be walked to a yen target
at all.
Deriving costs about a quarter of a second per market-day, so a market-year is
a minute and a half. MarketPrice is around an eighth the size of the bronze
it reads.
Nothing is dropped silently. MarketPrice holds only snapshots with a
real price. A size the visible book cannot fill is left out rather than priced
as a partial fill, and so is a snapshot whose walked spread exceeds 100 bps:
those are collector artefacts from a resync, present in historical bronze. How
many of each a day held is written into the file (df.attrs["dropped"] after
pd.read_parquet) and printed by hase derive, because it is a fact about the
archive worth being able to count.
Spread and volatility: one calculation, any parameters
Every spread and volatility figure Hase makes comes from one function,
hase.derive.vol_spread.measure, and VolSpread is that function stored on a
grid. Code that needs the figures on a grid of its own -- a labeller
resampling ticks, say -- calls measure rather than writing the formula again.
VolSpread is measured either at the top of the book (the default) or on what
a size would actually pay (--execution-size, read from MarketPrice). Its
windows are parameters, and each set is its own partition, so any number sit
side by side:
gold/dataset=VolSpread/exchange=GMO/symbol=BTC_JPY/execution_size=0.002/param_id=vs_60_300_120_1s/date=2026-06-01/data.parquet
gold/dataset=VolSpread/exchange=GMO/symbol=BTC_JPY/execution_size=touch/param_id=vs_60_300_120_1s/date=2026-06-01/data.parquet
vs_<horizon>_<lookback>_<smooth>_<step>s: --horizon is the return the
volatility is measured on, --lookback the window it is measured over (and the
spread's EMA span), --smooth the EMA span of the volatility, and --step the
grid, all in seconds. --params H:L:S, repeated, derives several sets from one
read of each day.
| Column | What it is |
|---|---|
bid, ask, mid, spread, spread_pct, spread_bps |
The last quote in each step, carried through a step with no update |
rv_bps |
Realized volatility over lookback: root of the summed squared one-step log returns, in bps |
volatility_raw |
Standard deviation of horizon returns over lookback, as a fraction |
volatility_ema, spread_pct_ema |
Those smoothed over smooth and lookback |
vol_spread_ratio |
volatility_ema / spread_pct_ema: how far price moves for what a round trip costs |
Each day is read with the eight hours before it, so the windows at 00:00 JST are full when the previous day is on disk; without it, they are NaN until a window has passed.
Agreement with the pipeline that produced the data
Hase reimplements these derivations rather than importing them from the
pipeline that built the archive, because a tool you install must not depend on
trading code. That is only safe if the two agree, so the test suite checks
MarketPrice against the pipeline's own stored output where that warehouse is
mounted, and skips where it is not. Measured on a full day of
COINCHECK:BTC_SPOT and GMO:BTC_JPY, the largest relative difference is
4e-16 — floating-point last-bit, from accumulating the levels in a different
order. VolSpread at an execution size agrees with the warehouse pipeline's
stored files to 2e-9 relative on every column, and the test suite holds the
same formulas written out independently.
Bronze as trading data
For code that trades rather than plots -- a backtest, a strategy's research
notebook -- hase.bronze returns qate's
objects rather than dataframes:
from hase import bronze
from hase.bronze import DataType
from qate.core.model import Market
market = Market.from_str("BINANCE:BTC_USDT")
bronze.markets() # [Market, ...] on disk
bronze.dates(market, DataType.ORDER_BOOK) # complete JST days
books = bronze.load(market, DataType.ORDER_BOOK, "2026-09-01", "2026-09-07")
load is strict: a missing day raises rather than reading as a quiet market.
load_day is the same for one day.
Hase asks Komachi which file holds each market-day (komachi.bronze.file)
and opens it; Komachi never looks inside a file, and Hase never builds a bronze
path. That is the whole division: Komachi places files, Hase reads them as
trading data.
It holds no credential
Hase reads local files. It reaches no API, holds no token, and knows nothing about entitlement or billing. That single rule is what lets one tool serve both as a customer product and as an analysis environment for data you already have: point it at a Komachi download or at your own warehouse, and it behaves the same.
If a day is missing, Hase says so and tells you the komachi command that
would fetch it. It will not fetch anything itself.
Where it reads from
--root, then ROOT_PATH in the environment, then ROOT_PATH in
~/.kamakuraquantlab.env, then ~/kamakuraquantlab-data. That file is the one
Komachi writes on first use, so the two tools agree without being configured
twice — and if Hase is installed first, it asks the same question and writes
the same file.
Hase does not work that order out for itself: it calls komachi.data_root(),
which is why kamakuraquantlab-komachi is a dependency. Hase reads the tree
Komachi downloads into, so Komachi is what says where the tree is. Your own
code can ask the same way — komachi.data_root() with nothing passed is the
settings file and nothing else, no environment, no default.
Only the data root comes across. The file also holds Komachi's purchase token, and Hase has no use for one.
<root>/bronze/dataset=Trade/exchange=COINCHECK/symbol=BTC_SPOT/date=2025-07-01/data.parquet
Dates are Tokyo days
A date partition holds the rows falling in [00:00 JST, 24:00 JST), which is
15:00 to 14:59 UTC. Timestamps inside the files are UTC epochs.
Plots are labelled in JST, matching the day they were cut in. This needs saying
because matplotlib converts datetimes to plain floats and forgets the zone: a
tz-aware series plots in the right place but is labelled in UTC unless the
formatter is told otherwise. A chart titled JST with a UTC axis is worse than
one with no timezone at all, so plot/style.py owns the zone and every axis
gets it explicitly.
What the plots do
plot-trades — price across the day, with buy and sell volume beneath.
Volume is bucketed (--bucket, default 5min) because a day is tens of
thousands of trades and a bar each is an unreadable smear. Buys and sells are
drawn apart rather than combined, since their balance is the reason to look.
plot-book — best bid and ask, with the spread beneath. Resampled to 1s
by default: a day is around 230,000 snapshots, more points than the chart has
pixels. --no-resample keeps every one for a short window where the detail
matters. Resampling takes the last value in each interval rather than the mean,
because a mean of neighbouring quotes is a price that never existed and the
spread between two such means can come out negative.
The spread panel clips its view to the 99.5th percentile and labels how many points fall above the cut. A few momentary wide spreads would otherwise set the scale and flatten the rest of the day into a line, and hiding them silently would be worse than saying how many there were.
Not yet built
Lead-lag, InfluxDB and Grafana export. The lead-lag plot is the piece with no reference implementation.
Tests
python -m pytest tests -q
Fixtures write real parquet to a temporary directory. No network, no credentials, no display.
Metadata
Release files for kamakuraquantlab-hase 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kamakuraquantlab_hase-0.9.0.tar.gz | 46.3 kB | Without provenance | Details for kamakuraquantlab_hase-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kamakuraquantlab_hase-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for kamakuraquantlab_hase-0.9.0-py3-none-any.whl |
Total release size: 85.2 kB
Release files / kamakuraquantlab_hase-0.9.0.tar.gz
| Download URL | kamakuraquantlab_hase-0.9.0.tar.gz |
|---|---|
| Size | 46.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
120e95115f65bf399a6f11426feddb65f317fc932fe51f16c1b56a358350f1fb
|
|
BLAKE2b-256 checksum How to use checksums |
33f5796fbe5733c698a376908c6dfbc0854f85ba4c23a57e6e69367d6e47d5d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Release files / kamakuraquantlab_hase-0.9.0-py3-none-any.whl
| Download URL | kamakuraquantlab_hase-0.9.0-py3-none-any.whl |
|---|---|
| Size | 38.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9040e2dc04ff7ec23f9d2958bb508dcf16c2910702c71f6a46f61141973562c
|
|
BLAKE2b-256 checksum How to use checksums |
d304b3b4d4c7841de35c5c9fd344fcc0f87ac6cd98feda27f6ada1c9aff63524
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Security for kamakuraquantlab-hase 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.