Transaction Cost Analysis in QuestDB with SQL

This title was summarized by AI from the post below.

Every trading desk wants to know whether its executions are any good. That's what transaction cost analysis is for, and it usually means paying for a separate, proprietary system to do it. You don't need one. If your ticks already sit in #QuestDB, the analysis is just a few SQL queries. We wrote up the whole pipeline, from capturing live ticks through to the summary tables a desk head would read. It captures live BTC-USDT ticks, simulates a TWAP order against them, and measures what that execution cost three ways: Whether the fills beat the market VWAP over the same window. Arrival slippage, fill by fill. An ASOF JOIN matches each execution back to the quote that was live the moment it was scheduled, so you see how far the price had already moved. The markout curve: where the mid went in the seconds and minutes after each fill. This is a HORIZON JOIN, a dozen time offsets per fill in one parallel pass, and it's the part most databases make painful. QuestDB does the SQL, Polars takes the per-fill results into summary tables.

  • No alternative text description for this image

Running TCA natively with ASOF and HORIZON joins is a massive architectural advantage for any trading desk. But the absolute correctness of that slippage calculation depends entirely on the physical determinism of the tick ingestion. When capturing live BTC-USDT ticks at extreme velocity, legacy OS kernels inevitably introduce I/O jitter. If the host VFS locking layer delays the log write by even a few milliseconds, the timestamp skews. When that happens, the arrival slippage calculation is fundamentally compromised before the SQL query even executes. To protect the mathematical purity of the tick data, the storage tier must bypass the OS entirely. By engineering Sovereign VFS to neutralize multi-tenant write-amplification at the bare metal, the ingestion CPU tax is strictly locked at ~1.4ms. QuestDB’s SQL optimizations are brilliant for executing the trade logic; completely bypassing the kernel is how you guarantee the underlying physical data is actually accurate.

See more comments

To view or add a comment, sign in

Explore content categories