Ultra-low latency AVX-512 Polymarket market-making kernel (Logit Jump-Diffusion + Avellaneda-Stoikov in logit space)
polymarket-kernel
Ultra-low latency computational core for Polymarket market making, now upgraded into a comprehensive decision-support and risk engine for prediction-market microstructure.
Repository Layout
packages/crates: Rust crate (polymarket-kernel)packages/npm: public npm packagepackages/bun: public Bun packagepackages/python: public PyPI packagedocs: additional project documentationtools: local release and utility scripts
Published Packages
- crates.io:
polymarket-kernel - npm:
holypolyfoundation-bs-p-npm - Bun (npm registry):
holypolyfoundation-bs-p-bun - PyPI:
bs-poly
Install
# Rust
cargo add polymarket-kernel
Node.js / npm
npm i holypolyfoundation-bs-p-npm
Bun
bun add holypolyfoundation-bs-p-bun
for native build in Bun, trust install scripts for this package:
add "trustedDependencies": ["holypolyfoundation-bs-p-bun"] to package.json
then run bun install
Python
pip install bs-poly
Usage Guide
Rust
use polymarketkernel::calculatequotes_logit;
fn main() { let x_t = vec![0.1]; let q_t = vec![0.0]; let sigma_b = vec![0.2]; let gamma = vec![0.08]; let tau = vec![0.5]; let k = vec![1.2];
let mut bid_p = vec![0.0; 1]; let mut ask_p = vec![0.0; 1];
calculatequoteslogit(&xt, &qt, &sigmab, &gamma, &tau, &k, &mut bidp, &mut ask_p); println!("bid={:.6}, ask={:.6}", bidp[0], askp[0]); }
Node.js / npm
import { sigmoid, logit, calculateQuotesLogit } from "holypolyfoundation-bs-p-npm";
console.log(sigmoid(0)); // 0.5 console.log(logit(0.5)); // 0
const out = calculateQuotesLogit([0.1], [0.0], [0.2], [0.08], [0.5], [1.2]); console.log(out.bidp, out.askp);
Bun
import { sigmoid, logit, calculateQuotesLogit } from "holypolyfoundation-bs-p-bun";
console.log(sigmoid(0)); // 0.5 console.log(logit(0.5)); // 0
const out = calculateQuotesLogit([0.1], [0.0], [0.2], [0.08], [0.5], [1.2]); console.log(out.bidp, out.askp);
Python
import bs_p
print(bs_p.healthcheck()) print(bs_p.sigmoid(0.0)) # 0.5 print(bs_p.logit(0.5)) # 0.0
out = bsp.calculatequotes_logit([0.1], [0.0], [0.2], [0.08], [0.5], [1.2]) print(out["bidp"], out["askp"])
Overview
polymarket-kernel implements a unified logit-space stochastic framework where probabilities are transformed into log-odds and processed through SIMD-native math.
The crate now combines:
- high-throughput quoting primitives
- inventory-aware execution math
- vectorized analytics and portfolio risk aggregation
Source paper:
Features
Core Quoting Kernel
- SoA (Structure of Arrays) layout for contiguous memory access and SIMD-friendly loads
- Runtime-dispatched AVX-512 quote acceleration with portable fallback
- Native NEON (aarch64) path with fully vectorized
exp/log1p/sigmoid/logit(~1-2 ulp) - Inventory-aware Avellaneda-Stoikov quoting in logit space
- Exact, numerically stable
sigmoid/logitmapping across the public API (logitkeeps full relative accuracy near p = 0.5 via alog1pformulation)
Analytics Capabilities
- Implied Belief Volatility calibration from market bid/ask quotes (exact closed-form inversion, no iteration)
- Vectorized Stress-Testing (what-if analysis) for shocked probabilities, PnL shifts, and re-quoted books
- Adaptive Kelly sizing for maker and taker clip recommendations under inventory and risk constraints
- Order Book Microstructure metrics: OBI, VWM, and pressure signal in logit space
- Cross-Market Portfolio Greeks aggregation with optional weighting and correlation matrix support
Systems Properties
- C kernel in
packages/crates/c_src/with FFI-safe Rust bindings inpackages/crates/src/ - Portable scalar baseline that runs on any CPU
- Zero allocations in the hot path (pre-allocated caller-managed buffers)
- Runtime-dispatched AVX-512 fast path on supported server-class CPUs; compile-time NEON fast path on aarch64
- Shared SIMD math header (
csrc/pmsimd_math.h) with vectorizedexp/log/log1p/sigmoid/logitused by both quoting and analytics - Numerically safe clamping for stable
logitevaluation without saturating large logits - Lock-free SPSC ring buffer for market data handoff with cached-index design (producer and consumer avoid touching each other's cache line on the hot path)
Quick Start
Install:
cargo add polymarket-kernel
Call calculatequoteslogit with SoA input slices:
use polymarketkernel::calculatequotes_logit;
fn main() { let x_t = vec![0.15, -0.35, 0.90, -1.20]; let q_t = vec![10.0, -6.0, 3.0, 0.0]; let sigma_b = vec![0.22, 0.18, 0.30, 0.15]; let gamma = vec![0.08, 0.08, 0.08, 0.08]; let tau = vec![0.50, 0.50, 0.50, 0.50]; let k = vec![1.40, 1.25, 1.10, 1.80];
let mut bidp = vec![0.0; xt.len()]; let mut askp = vec![0.0; xt.len()];
calculatequoteslogit( &x_t, &q_t, &sigma_b, &gamma, &tau, &k, &mut bid_p, &mut ask_p, );
for i in 0..x_t.len() { println!("market {i}: bid={:.6}, ask={:.6}", bidp[i], askp[i]); } }
Analytics API Example
use polymarket_kernel::{analytics, GreekOut};
fn main() { let n = 4usize;
let bid_p = vec![0.49, 0.41, 0.62, 0.23]; let ask_p = vec![0.52, 0.45, 0.66, 0.27]; let q_t = vec![8.0, -4.0, 2.0, 0.0]; let gamma = vec![0.08; n]; let tau = vec![0.5; n]; let k = vec![1.4; n];
let mut implied_sigma = vec![0.0; n]; analytics::impliedbeliefvolatility_batch( &bid_p, &ask_p, &q_t, &gamma, &tau, &k, &mut implied_sigma, );
// q_t is retained for API-shape consistency, but the current calibration // formula depends on spread, gamma, tau, and k. let x_t = vec![0.20, -0.40, 0.70, -1.10]; let shock_p = vec![0.01, -0.02, 0.03, -0.01];
let mut outrx = vec![0.0; n]; let mut out_bid = vec![0.0; n]; let mut out_ask = vec![0.0; n]; let mut out_greeks = vec![GreekOut::default(); n]; let mut out_pnl = vec![0.0; n];
analytics::simulateshocklogit_batch( &x_t, &q_t, &implied_sigma, &gamma, &tau, &k, &shock_p, &mut outrx, &mut out_bid, &mut out_ask, &mut out_greeks, &mut out_pnl, );
println!("implied sigma: {implied_sigma:?}"); println!("stress pnl shift: {out_pnl:?}"); }
Benchmark Snapshot
Apple M4 (aarch64, NEON path):
============================================================
POLYMARKET-KERNEL RAW BENCHMARK
============================================================
Quote Batch Size : 8192 markets
Quote Iterations : 100000
Runtime-Dispatch Quote : 5.78 ns/market
Sigmoid Batch : 1.20 ns/element
Implied Vol Calibration : 5.78 ns/market
SPSC Ring Capacity : 1048576
SPSC Messages : 10000000
SPSC Throughput : 188.42 M msgs/sec
============================================================
For reference, the same host on the previous scalar-fallback build measured 11.07 ns/market for quotes and 55.9 M msgs/sec for the SPSC ring (~1.9x and ~3.4x respectively).