Exact tick data: market data as small integers
Prices are counted in ticks and sizes in lots, so most market-data arithmetic has one exact integer answer. This paper measures what it costs to get that answer on every machine, against the best C we could write, including hand-written vector intrinsics, and against the usual Python tools.
Abstract
On 1 December 2026 Riptide ran six market-data computations on three AWS server CPUs, one thread each, with every input held as integers: prices in ticks, sizes in lots, counts as counts. Each computation was written once as plain Raya loops and measured against plain C, against a C twin of the same byte-limb reformulation Raya uses, against hand-written C vector intrinsics (Arm UDOT/USDOT, AVX-512 VNNI), and against NumPy, pandas, polars, numba and SciPy at their fastest settings. The data are a seeded synthetic data set built to the shapes of real exchange data (random-walk ticks, log-normal lot sizes, Poisson trade arrivals). Every exact implementation, on every CPU, returned the same 64-bit checksum of every output (378 runs, one checksum per case).
Lead–lag correlation. Cross-products of trade counts over 8,640,000 bins of 10 ms ran 2.7–4.1× faster than plain C at 1,024 lags and 1.7–3.1× at 256 lags. Against hand-written intrinsics that share every tap load across 8 lags, plain Raya was 0.94–1.10× as fast at 1,024 lags (a tie), but 0.41–0.83× at 256 lags and 0.19–0.30× at 32 lags. At 1,024 lags it was 2.4–5.1× faster than SciPy's FFT correlation.
P&L distributions, VaR and expected shortfall. The exact distribution of a 2-asset and a 4-asset portfolio's one-minute P&L, built as products of count polynumbers, took 0.014–0.24 ms in plain Raya on the synthetic histograms, 1.1–2.9× faster than the best of plain C and a C byte-limb twin (no intrinsics version was written for this case). For 4 assets this times the final product of the two pair products, which are built once during data preparation. Splitting the counts into byte limbs took 1.1–1.9× as long as the product for 2 assets and 37–70% of it for 4 assets; including it, Raya was 0.62–1.30× the best C's speed. VaR and expected shortfall at 97.5% come out as exact rationals; Monte Carlo with 10 million draws took 1.19–1.32 s and its expected shortfall was off by 0.042–0.044% (median of 10 seeds), up to 0.11%.
Where float goes wrong. Over 200,000 sampled windows, the float64 rolling variance was correctly rounded on under 1% of windows by every float method measured: pandas, polars, prices relative to a reference, Welford's update and a two-pass computation per window. Their worst errors ranged from 7.9 × 10⁻¹³ (polars on relative prices) to 2.3 × 10⁻³ (pandas on absolute prices). The exact path is integer sums and one division.
Where Raya is not faster. Hand-written intrinsics beat plain Raya for weighted volume at price at every window (0.44–0.81×), and Raya's byte-limb split for that case was slow enough to dominate. Rolling window sums ran at 0.17–0.51× of C and top-of-book features at 0.30–0.96×; numba and polars on 64-bit integers were faster than Raya on both. SciPy's FFT built the 4-asset P&L distribution 1.7–3.6× faster than Raya, but only 41–47% of its counts were exact.
The numbers in this paper are from the synthetic data set. The same tests were also run on public exchange data (Binance Vision [8], licensed for non-commercial use, so its measurements are not published here): every exact implementation gave the same checksums, the lead–lag and volume-at-price ratios were similar, and on the P&L products plain Raya was behind the best C on Graviton4 and Zen 4 and the FFT's lead was larger.
What this lets you do
- Get one answer on every machine. Integer ticks and lots, integer sums and one division at the end give the same VWAP, variance, smoothed volume, correlation and risk number on Arm and x86, in C, Raya, NumPy or numba.
- Write the loop plainly and get vector speed. Plain Raya loops were 1.7–4.1× faster than the same loops in plain C for lead–lag at 256 and 1,024 lags, and matched hand-written intrinsics at 1,024 lags, without intrinsics in the source.
- Read VaR and expected shortfall from an exact distribution instead of estimating them. For independent legs, the product of their P&L polynumbers is the portfolio's distribution; the tail is read from its coefficients, with no sampling noise.
- Know which windows your float pipeline gets wrong. Every float variance method measured missed the correctly rounded value on nearly every window; the size of the miss ranged over nearly ten orders of magnitude depending on the method.

Results
Lead–lag cross-correlation
The question a lead–lag study asks: when one instrument trades, how many trades of the other follow, bins later? With and the trade counts per 10 ms bin over one day (8,640,000 bins), the exact cross-products are for . In the synthetic data the two arrival streams are independent, so this is a speed and exactness test, not a lead–lag finding.
| Lags | CPU | Raya | Raya limb split | Plain C | C byte-limb twin | C intrinsics | C intrinsics, 8 lags per pass | SciPy auto | SciPy FFT | Raya vs best C | Raya vs plain C |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 32 | Graviton4 | 37.4 | 9.32 | 50.9 | 37.0 | 31.5 | 11.1 | 27.9 | 768 | 0.30× | 1.36× |
| 32 | Sapphire Rapids | 35.8 | 6.09 | 32.9 | 49.8 | 47.5 | 6.90 | 56.5 | 1,151 | 0.19× | 0.92× |
| 32 | EPYC Zen 4 | 25.9 | 7.10 | 34.4 | 23.5 | 24.6 | 7.16 | 90.0 | 973 | 0.28× | 1.33× |
| 256 | Graviton4 | 105 | 9.33 | 322 | 295 | 250 | 86.7 | 223 | 776 | 0.83× | 3.06× |
| 256 | Sapphire Rapids | 130 | 6.11 | 222 | 397 | 379 | 53.8 | 452 | 1,152 | 0.41× | 1.71× |
| 256 | EPYC Zen 4 | 90.2 | 7.11 | 162 | 193 | 207 | 57.2 | 720 | 960 | 0.63× | 1.79× |
| 1,024 | Graviton4 | 314 | 9.32 | 1,291 | 1,162 | 999 | 344 | 771 | 767 | 1.10× | 4.11× |
| 1,024 | Sapphire Rapids | 224 | 6.14 | 926 | 1,618 | 1,542 | 218 | 1,154 | 1,149 | 0.97× | 4.13× |
| 1,024 | EPYC Zen 4 | 243 | 7.11 | 647 | 773 | 800 | 229 | 971 | 964 | 0.94× | 2.67× |
SciPy's auto method chose direct summation in float64 at 32 and 256 lags and the FFT at 1,024 lags; with these small counts every float64 result rounded to the exact integer. On Graviton4 SciPy auto was faster than plain Raya at 32 lags (27.9 against 37.4 ms).
Weighted volume at price
The trades, summed by price tick, form a polynumber : the coefficient at tick is the traded volume at that price (5,799 ticks wide, up to 11,053,344 lots at one tick). A centred triangular smoothing with int8 weights that peak at the middle of the window gives .
| Window | CPU | Raya | Raya limb split | Plain C | C byte-limb twin | C intrinsics | C intrinsics, 8 outputs per pass | numba | SciPy auto | Raya vs best C | incl. split |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 16 ticks | Graviton4 | 0.0277 | 0.192 | 0.0193 | 0.0221 | 0.017 | 0.0122 | 0.0196 | 0.0938 | 0.44× | 0.06× |
| 16 ticks | Sapphire Rapids | 0.0233 | 0.182 | 0.022 | 0.0301 | 0.0199 | 0.0112 | 0.0221 | 0.0555 | 0.48× | 0.05× |
| 16 ticks | EPYC Zen 4 | 0.0216 | 0.187 | 0.0145 | 0.0289 | 0.017 | 0.0113 | 0.0141 | 0.0485 | 0.52× | 0.05× |
| 64 ticks | Graviton4 | 0.0399 | 0.193 | 0.0748 | 0.0435 | 0.0373 | 0.0204 | 0.075 | 0.132 | 0.51× | 0.09× |
| 64 ticks | Sapphire Rapids | 0.0319 | 0.18 | 0.0814 | 0.0297 | 0.0298 | 0.0259 | 0.0743 | 0.0652 | 0.81× | 0.12× |
| 64 ticks | EPYC Zen 4 | 0.0316 | 0.186 | 0.0561 | 0.025 | 0.024 | 0.0215 | 0.0609 | 0.0783 | 0.68× | 0.10× |
| 256 ticks | Graviton4 | 0.0862 | 0.192 | 0.29 | 0.129 | 0.109 | 0.0668 | 0.287 | 0.308 | 0.77× | 0.24× |
| 256 ticks | Sapphire Rapids | 0.0654 | 0.18 | 0.323 | 0.0613 | 0.0453 | 0.0362 | 0.325 | 0.147 | 0.55× | 0.15× |
| 256 ticks | EPYC Zen 4 | 0.0702 | 0.186 | 0.228 | 0.0561 | 0.0551 | 0.04 | 0.207 | 0.159 | 0.57× | 0.16× |
P&L distribution, VaR and expected shortfall
Each leg's one-minute P&L over 44,640 minutes (positions of 10 BTC, 300 ETH, 6,000 SOL and 1,000 BNB, worth $0.90–0.96 million each at the start) was binned once to $10 and counted, giving one polynumber of counts per leg. Assuming the legs are independent, the portfolio's P&L distribution is the product of those polynumbers. The 4-asset product is (BTC × ETH) × (SOL × BNB); only the final product is timed, because the two pair products are built once during data preparation; its counts sum to 44,640⁴ = 3,970,971,258,716,160,000 (every combination of four minutes), below 2⁶³.
| Portfolio | CPU | Raya | Raya limb split | Plain C | C byte-limb twin | numba | SciPy direct (int64) | SciPy FFT | FFT counts exact | Raya vs best C | incl. split |
|---|---|---|---|---|---|---|---|---|---|---|---|
| BTC + ETH | Graviton4 | 0.0256 | 0.0284 | 0.0528 | 0.0437 | 0.0491 | 0.153 | 0.0494 | 100.0% | 1.71× | 0.81× |
| BTC + ETH | Sapphire Rapids | 0.0142 | 0.0263 | 0.0497 | 0.0416 | 0.0503 | 0.135 | 0.05 | 100.0% | 2.93× | 1.03× |
| BTC + ETH | EPYC Zen 4 | 0.0182 | 0.0285 | 0.029 | 0.0328 | 0.033 | 0.186 | 0.0434 | 100.0% | 1.60× | 0.62× |
| 4 assets | Graviton4 | 0.238 | 0.088 | 0.298 | 0.658 | 0.273 | 0.705 | 0.0667 | 46.5% | 1.25× | 0.92× |
| 4 assets | Sapphire Rapids | 0.117 | 0.082 | 0.257 | 0.713 | 0.273 | 0.626 | 0.0674 | 40.7% | 2.21× | 1.30× |
| 4 assets | EPYC Zen 4 | 0.149 | 0.0877 | 0.163 | 0.527 | 0.19 | 0.879 | 0.0576 | 40.7% | 1.10× | 0.69× |
The exact 97.5% VaR and expected shortfall are $1,900 and $2,270.23 for BTC + ETH and $3,050 and $3,647.28 for the 4-asset portfolio. SciPy's FFT counts for 4 assets were off by up to 6, and differed between Graviton4 and the two x86 CPUs, but the expected shortfall computed from them matched the exact value to about 1 part in 10¹⁴. SciPy's auto method chose direct float64 summation for this case; its counts were exact on Graviton4 and 97.4% exact on the x86 CPUs, where the largest sums pass 2⁵³.
| Portfolio | Draws | Time (median) | ES error, median of 10 seeds | ES error, worst seed | VaR across seeds |
|---|---|---|---|---|---|
| BTC + ETH | 1 million | 122 ms | 0.09% | 0.20% | $1,890–1,900 |
| BTC + ETH | 10 million | 1.19 s | 0.04% | 0.11% | $1,900 |
| 4 assets | 1 million | 134 ms | 0.10% | 0.21% | $3,040–3,050 |
| 4 assets | 10 million | 1.32 s | 0.04% | 0.11% | $3,050 |
Rolling VWAP and variance
Over 2,000,000 trades, each window of trades needs , , and ; VWAP and variance follow from them.
| Window | CPU | Raya | Faster C | numba | polars (Int64) | NumPy cumsum | pandas (float64) | polars (float64) | Raya vs C |
|---|---|---|---|---|---|---|---|---|---|
| 100 trades | Graviton4 | 11.6 | 5.67 | 5.76 | 6.88 | 32.0 | 120 | 60.3 | 0.49× |
| 100 trades | Sapphire Rapids | 12.1 | 6.08 | 6.36 | 11.6 | 51.8 | 167 | 41.7 | 0.50× |
| 100 trades | EPYC Zen 4 | 25.5 | 4.80 | 5.09 | 7.32 | 23.4 | 128 | 44.5 | 0.19× |
| 1,000 trades | Graviton4 | 11.7 | 5.41 | 6.09 | 6.90 | 32.0 | 120 | 60.9 | 0.46× |
| 1,000 trades | Sapphire Rapids | 12.2 | 6.22 | 6.53 | 12.1 | 51.4 | 159 | 42.1 | 0.51× |
| 1,000 trades | EPYC Zen 4 | 30.7 | 5.37 | 4.69 | 7.33 | 23.0 | 130 | 45.6 | 0.17× |
| Method | Time, 100 trades (ms) | Variance not correctly rounded, 100 / 1,000 trades | Worst variance error, 100 / 1,000 trades |
|---|---|---|---|
pandas rolling().var(), absolute prices | 120–167 | 100% / 100% | 2.3 × 10⁻³ / 1.3 × 10⁻⁴ |
polars rolling_var, absolute prices | 41.7–60.3 | 100% / 100% | 2.0 × 10⁻⁹ / 1.8 × 10⁻⁹ |
| pandas, prices relative to the first trade | 32.2–39.5 | 99.999% / 99.999% | 3.0 × 10⁻⁷ / 3.3 × 10⁻⁸ |
| polars, prices relative to the first trade | 34.4–46.4 | 99.375% / 99.496% | 7.9 × 10⁻¹³ / 8.8 × 10⁻¹³ |
| Welford, add/remove updates (numba) | 4.54–5.11 | 100% / 100% | 7.4 × 10⁻⁴ / 1.6 × 10⁻⁴ |
| Two-pass per window (numba) | 225–291 | 99.999% / 99.997% | 2.0 × 10⁻¹⁰ / 2.0 × 10⁻¹¹ |
| Exact integer sums, one division (C) | 4.80–6.08 | 0% / 0% | 0 / 0 |

The float64 VWAP was not correctly rounded on 93.1% of 100-trade windows and 47.4% of 1,000-trade windows, in both pandas and polars, with worst errors of 3.5 × 10⁻¹⁵ and 4.3 × 10⁻¹⁶. pandas' rolling var keeps running sums and updates them as each value enters and leaves the window; on absolute prices the variance is a small difference of large sums, which is where it loses digits (the classical analyses are Welford [2], Chan, Golub and LeVeque [3] and Higham [7]). Subtracting a reference price and computing each window twice both shrink the error; neither makes the result correctly rounded. The two-pass method was also the slowest, 2.3–3.2 s per call for 1,000-trade windows.
Top-of-book features
For each of 20,000,000 best-bid/offer updates: the queue-imbalance numerator and denominator (, ), the microprice numerator , and the spread . Every value fits well inside 2⁵³, so one float64 division of the numerator by the denominator is already correctly rounded; this case is about speed, not exactness.
| CPU | Raya | Faster C | numba | polars (Int64) | NumPy | pandas (Int64) | Raya vs C |
|---|---|---|---|---|---|---|---|
| Graviton4 | 111 | 39.4 | 37.5 | 28.4 | 74.1 | 80.3 | 0.35× |
| Sapphire Rapids | 98.5 | 94.5 | 95.0 | 84.4 | 270 | 296 | 0.96× |
| EPYC Zen 4 | 132 | 39.5 | 33.8 | 53.0 | 90.9 | 100 | 0.30× |
Method
Everything below is computed in integers and is exact by construction; each step states the bound that keeps it inside 64 bits.
- Integers once. Prices are converted to ticks (0.01 for spot trades, 0.1 for the book), sizes to lots, each conversion checked to land on the grid. No floating point touches the data after that.
- Rolling sums. Running sums over the window add the newest trade and subtract the one leaving. Prices are taken relative to the first trade, so and the variance numerator stay below 2⁶³; the exact variance is that numerator over , and the exact VWAP is , a rational. One division at the end gives the correctly rounded float64 if one is needed.
- Lead–lag as an FIR. The cross-products are an FIR filter loop with one instrument's counts as 16-bit taps and the other's as the signal. The signal is split into two byte limbs, , and two byte-FIR passes give , exact in 64 bits. The non-synchronous lead–lag literature (Hayashi and Yoshida [5]) works on the same cross-products; the FFT route is the Cooley–Tukey transform [4].
- Volume at price. is split into byte limbs (three here, since ), each limb is filtered by the int8 weights, and the results are shifted and added. The true sums are below 2⁶³, so the 64-bit sum is exact.
- P&L distributions as polynumber products. Each leg's histogram of binned P&L is a polynumber of counts; the product of two such polynumbers counts every pair of outcomes, so it is the distribution of the sum under independence, the same convolution Panjer's recursion [6] evaluates for aggregate losses. The counts are split into byte limbs and each limb pair is one byte polynumber product; the results are shifted and added. VaR and expected shortfall at 97.5% are read from the exact counts with the discrete form of Acerbi and Tasche [1], including the fractional share of the bin at the quantile, as exact rationals.
- The compiler. Plain Raya compiled ahead of time recognises the FIR loop and the byte polynumber product and runs a kernel chosen for the CPU (Arm
UDOT/USDOTon Graviton4; AVX-512 VNNIVPDPWSSDandVPDPBUSDon the x86 CPUs), as described in "Plain Raya integer loops, faster than C". The run trace confirmed a kernel ran for every lead–lag, depth and P&L case. Rolling sums and book features are not kernel shapes. The byte-limb split is done in plain Raya before the timed loop and timed separately. - The C baselines. Plain C is the same loop on int64. The byte-limb twin is the same reformulation as Raya's, written as plain C on uint8 limbs with int32 accumulators flushed to int64 inside a proven bound, so gcc and clang can vectorise it themselves. The intrinsics versions are hand-written: lead–lag splits the int16 taps into an unsigned low byte and a signed high byte and uses
UDOTandUSDOTon Arm, or usesVPDPWSSDon 16-bit pairs on x86; depth usesUSDOTorVPDPBUSD. Each has a register-blocked form in which 8 lags (or 8 outputs) share every tap (or weight) load. All C versions are compiled with gcc and with clang and checked against the plain loop's checksum before timing. - The Python baselines. NumPy, numba and SciPy direct summation on int64 are exact; SciPy
autoand the FFT run in float64 and their results are compared with the exact values. The float variance baselines are pandas and polars on absolute and on reference-relative prices, Welford's add/remove update and a two-pass computation per window (numba). - Checking. Every exact implementation prints a wrapping 64-bit checksum, folded across output arrays; all of them agreed on every case and CPU. Float results are compared with exact values computed in Python integers and fractions.
Setup
- Machines: AWS EC2 us-west-2, one thread each: c8g.2xlarge (AWS Graviton4, Neoverse V2), c7i.2xlarge (Intel Xeon Platinum 8488C, Sapphire Rapids), c7a.2xlarge (AMD EPYC 9R14, Zen 4). Ubuntu 24.04.
- Compilers: gcc 13.3.0 and clang 18.1.3 at
-O3 -march=native. - Python: 3.12.3 with NumPy 2.5.5, pandas 3.1.2, polars 2.2.0, numba 0.68.1, SciPy 1.18.1 (recorded on each machine).
- Timing: best of 5 blocks of at least 60 ms per call; Monte Carlo timed per run (median of 10 seeds). The weighted-volume group on the two x86 CPUs was rerun in one later session on the same machines so that every column of that table comes from one session.
- Data: the synthetic set has 2,000,000 trades for the rolling case, two independent Poisson arrival streams for lead–lag, 20,000,000 book updates and four random-walk minute price series of 44,641 closes; it is seeded and reproducible.
- Cost: about $2 of EC2 time for the runs reported here.
Limitations and next steps
The limits of these results, each with its cause and, where one is planned, the next step.
- Lead–lag at 32 and 256 lags: 0.19–0.30× and 0.41–0.83× of hand-written intrinsics. Cause: under investigation. The hand-written version shares every tap load across 8 lags; whether the compiler's kernel does the equivalent at small lag counts is being checked.
- Weighted volume at price: 0.44–0.81× of hand-written intrinsics, and 0.05–0.24× including the limb split. Cause: the register-blocked intrinsics share each weight load across 8 outputs; and the byte-limb split is written in the benchmark as general list-building code that allocates, which costs more than the filter itself.
- Rolling window sums: 0.17–0.51× of C; numba and polars on Int64 were also faster than Raya. Cause: a running sum is not a kernel shape, so Raya's own code generator runs it, and its 64-bit scalar loops are slower than gcc's, clang's and LLVM's (numba); why EPYC Zen 4 is slowest is under investigation.
- Top-of-book features: 0.30–0.96× of C; polars on Int64 was the fastest implementation on Graviton4 and Sapphire Rapids, and numba matched or beat C. Cause: element-wise 64-bit arithmetic is not a kernel shape.
- numba beat Raya on rolling sums, book features and the 16-tick volume window. Cause: numba compiles through LLVM, as clang does; those cases run in Raya's own code generator, not a kernel.
- P&L: the byte-limb split is costly (1.1–1.9× the product for 2 assets, 37–70% of it for 4 assets). Including it, Raya was 0.62–1.30× of the best C. No intrinsics C version was written for this case, so the comparison is against plain C and the byte-limb twin only. Cause: the split is the same general list-building code as above.
- SciPy's FFT built the 4-asset P&L distribution 1.7–3.6× faster. Cause: an FFT costs against for the direct product. Only 41–47% of its counts were exact and they differed between CPU families, though the expected shortfall was unaffected at this size.
- The fast path needs a Raya build. The kernels run only in ahead-of-time Raya programs; there is no Python binding yet, which is where most quant research happens. Cause: not built yet.
- CPUs only. Cause: GPU batch versions of these computations were not part of this campaign.
- Independence. The P&L product assumes the legs move independently; real portfolios need historical scenarios, which are exact integer sums in the same framework. Cause: not measured here.
Reproduce it yourself
Run kits/exact-tick-data from the public riptide-reproduce repository: one command, a few minutes on a laptop, public software only. It reproduces how often pandas, polars and two-pass float64 return the correctly rounded rolling variance, and exact lead–lag products against SciPy's FFT; the same exact sums in plain Raya 0.4.0 loops print the same checksums. Every baseline's value and its error against the exact answer are printed and saved to errors.csv, and the exact results print the same hash on every machine: if your float hash differs from ours or a colleague's, that is precision drift in your pipeline.
References
- C. Acerbi and D. Tasche, "On the coherence of expected shortfall", Journal of Banking & Finance 26(7), 2002, 1487–1503. doi:10.1016/S0378-4266(02)00283-2
- B. P. Welford, "Note on a method for calculating corrected sums of squares and products", Technometrics 4(3), 1962, 419–420. doi:10.1080/00401706.1962.10490022
- T. F. Chan, G. H. Golub and R. J. LeVeque, "Algorithms for computing the sample variance: analysis and recommendations", The American Statistician 37(3), 1983, 242–247. doi:10.1080/00031305.1983.10483115
- J. W. Cooley and J. W. Tukey, "An algorithm for the machine calculation of complex Fourier series", Mathematics of Computation 19, 1965, 297–301. doi:10.1090/S0025-5718-1965-0178586-1
- T. Hayashi and N. Yoshida, "On covariance estimation of non-synchronously observed diffusion processes", Bernoulli 11(2), 2005, 359–379. doi:10.3150/bj/1116340299
- H. H. Panjer, "Recursive evaluation of a family of compound distributions", ASTIN Bulletin 12(1), 1981, 22–26. doi:10.1017/S0515036100006796
- N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd ed., SIAM, 2002.
- Binance Vision public data, data.binance.vision (CC BY-NC-SA 4.0).
Working with Riptide
Riptide works with a small number of teams. Each engagement starts with 4 weeks inside your systems, learning how your models, data and infrastructure work. Only then does Riptide apply its software to them. Contact samario@riptidecompute.com or riptidecompute.com/evaluate.
Date and version
Version 1.2, 1 December 2026. Updated 1 December 2026: limitations section retitled. Updated 1 December 2026: added "Reproduce it yourself".