Skip to content

Xylem-Group/kos

Repository files navigation

kos

CI License: CC BY-NC 4.0 Python 3.11+ Ruff

Measurement primitives for perp microstructure research. Reference implementations of the metrics we use at Xylem Group, published as a runnable companion to our research notes. If you read a method described in prose, you can run it on your own data.

Three primitives — markout, vpin, if_stress — each in kos/<name>.py with a synthetic notebook demo in examples/ and tests in tests/. Real-data demos and applied research live in the sister repo paros, which builds on these primitives.

Primitives

markout — per-fill price drift in bps

How much does the mid move against you after a fill? Computed in basis points across log-spaced horizons from sub-millisecond to one minute. Three normalizations: by half-spread, by realized volatility, by an impact prior. The foundation for any signal-toxicity measurement.

Markout curve, synthetic adversely-selected buy

vpin — volume-synchronized probability of informed trading

Easley/López de Prado/O'Hara's classic toxicity proxy. Bulk volume classification with a normal CDF, fixed-volume buckets, rolling toxicity score. Plus notes on what doesn't translate cleanly to crypto perps.

VPIN regime change on synthetic tape

if_stress — insurance-fund stress simulator

Given a population of leveraged longs and a price shock, walks the liquidation cascade: surplus to the IF, depletion timing, ADL queue. Sweep if_initial to find the smallest IF that survives a given shock with target probability.

IF survival curve

Real-data work — see paros

The headline cross-venue demo (Hyperliquid BTC vs Binance USDT-M BTCUSDT, mid-path overlay + cross-venue basis + 500-fill markout distribution per venue) lives in paros, our applied research repo. paros imports kos for the primitives and adds the data adapters, real-data notebooks, governance specs, and benchmark tables. Treat kos as the library; paros as the applied book.

Running

uv sync                                # installs kos + dev deps
uv run jupyter lab examples/           # opens the synthetic-demo notebooks

Or render the README plots from a clean checkout:

uv run python scripts/render_plots.py

Tests:

make test

Scope and limitations

  • kos is a primitives library. Every demo here runs on synthetic data with zero external-data dependencies. Reproducibility on a fresh clone is uv sync && make demo.
  • Real-data work lives in paros. That keeps kos honest about what it is (algorithms + their unit tests) and pushes data-source coupling, venue calibrations, and applied research into a separate repo where it belongs.
  • VPIN crypto-perp caveats (volume clock × funding events, liquidation-driven one-sided volume, maker-taker fee asymmetries) are documented in kos/vpin.py. They affect interpretation, not the implementation.

License

CC BY-NC 4.0 — read, share, cite, run on your own data. No commercial redistribution. See LICENSE.

Citation

If you use these primitives in published work, please cite the repo. See CITATION.cff for the canonical record.

About

Measurement primitives for perp microstructure research

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors