Spread Liquidity Study

Software · Short case

Spread Liquidity Study SP流动性相关性

A desk rule of thumb, tested on hundreds of trading observations and answered with proof in 20 minutes, with a separate verdict for every product.

  • Designed, built and validated by Shuo Huang
  • 20 min 16 s from request to verified result
  • Reconciled to the lot on every day
  • Delivered 6 Aug 2026, in his second month on the desk
  • Question posed by a colleague

01System architecture

Two records of the desk’s trading and one read-only database pull, reconciled before a single coefficient.

The desk’s own orders sit in the trading terminal’s exports; exchange-wide volumes sit in the market-data database. The design pulls everything the study needs from the database in one click, so the analysis never waits on a second pull.

Trading terminal exports

Order exports

Daily files of every order the desk sent. Spread orders appear as their own rows.

Desk PC · Python

Extractor

Streams the exports and builds the base table: orders, filled orders and filled lots per day and spread.

Desk PC · Python

Estimator

Joins everything into one row per traded spread and day. Pearson and Spearman, per product and pooled.

Sent to the desk

Results graphic

One forwardable picture: every coefficient, every definition.

Trading terminal exports

Fill exports

Daily files of executed trades. An independent record of the same activity.

Desk PC · Python

Validator

Spread lots from orders must equal exchange-derived leg fills ÷ 2. Equal to the lot on every day.

Desk PC · Python

Parser

Splits the returned file into five datasets, one per query.

Read-only · one click

One-click SQL package

One click; the password is typed at run time and never stored. Five read-only queries, one results file, one error file.

Market-data database · MariaDB

Exchange and desk data

Daily volume of every contract, the exchange’s designated-contract lists, settlement fills.

Simplified: the raw exports were first frozen in a dated run folder, and the rendering script that draws the graphic is folded into the last node.

Why everything in one pull?

A pull that comes back short costs a second round trip and holds up the answer. So the package asked for more than the study needed: every contract of the desk’s ten market-making products plus related instruments, the exchange’s designated-contract lists for each month of the window, and the desk’s settlement fills as a second cross-check. The run came back with an empty error file.

Why a third source?

A correlation is only as good as the table under it. The order export and the fill export are written separately by the trading terminal, so agreement between them on every day is evidence the extraction is right, before any statistic is computed.

Who did what

The hypothesis and the variables to measure were a colleague’s.1 The data plan, the window, the one-pull workflow, the pipeline, the validation and the deliverable were Shuo’s.

02The story

A desk rule of thumb, tested on hundreds of observations in 20 minutes, with a verdict for every product.

A colleague had a rule of thumb for choosing which spread trades the desk should keep running: pick the ones whose underlying contracts are busiest. Shuo turned that rule into a test on the desk’s own trading, built the data pipeline for it from scratch, proved the data right against an independent record, and returned the answer 20 minutes after being asked.2 The rule held for some products and not for others, so the desk got a separate answer for each.3

  1. 01

    The problem

    The desk trades calendar spreads on the Dalian Commodity Exchange: one order that buys one delivery month of a product and sells another. The desk was reviewing which spreads to keep quoting and wanted a rule for choosing.

    A colleague proposed one: spreads whose two contracts trade heavily should suit larger spread orders. The colleague wrote down what to measure. Nobody had the numbers.

    • The data lived in two places. The desk’s orders were in the trading terminal’s exports; exchange-wide volumes were in the market-data database.
    • The exports were short-lived. The folder that held them keeps files only for a limited time.
    • The window was short. Only a recent stretch of trading was comparable from day to day, so every observation had to be right.
  2. 02

    What he built

    Shuo saw that the order exports feeding his own Spread Calculator already held everything on the order side, chose the longest clean window, and designed the workflow around a single database pull: write the queries once, pull everything in one click, compute on return.

    Think of checking a shopkeeper’s hunch that busy streets sell bigger baskets. You need the shop’s own receipts, the city’s foot-traffic counts, and a second set of books to prove the receipts were read correctly. This study is that, for every Dalian calendar spread the desk traded in the window.

    • Receipts: every spread order the desk sent, streamed from the terminal’s raw exports.
    • Foot traffic: the day’s market volume of every contract involved, pulled in one click.
    • Second set of books: the fill export, which agreed with the order export to the lot on every day.4

    The result went to the desk as a single picture with every definition printed under the table.

  3. 03

    What changed

    The rule of thumb became a per-product answer. Busier legs went with bigger spread fills clearly in two products, weakly in two, and not at all in two others, where the two estimators did not even agree on sign. The product with the most observations was one of those last two, so a single pooled number would have hidden both the products where the rule holds and the ones where it does not.3

    The study also established a fact about the exchange: every spread contract’s own volume field is zero, because spread trades are booked entirely to the two legs.5

    Four days later, the same pull’s copy of the exchange’s designated market-maker contract lists verified the list built into the self-trade checker: a match for all ten products.6

    Twenty minutes was possible because the foundations were already his, built in his first weeks on the desk: the order data, a map of the database he had drawn by hand in July (later automated as DB Structure Snapshot), and a one-click, read-only pull pattern.

20min

from the request to a verified answer, database pull included2

0lots

difference between the order record and an independent fill record, on every day of the window4

5

read-only queries in a single one-click pull, a deliberate superset so the study never waited on a second one

31min

from the request to a forwardable graphic with every coefficient and definition printed on it2

03Evidence

The rule holds in some products, not in others

Each cell is one correlation between fill size per order and the two legs’ market volume on the same day, computed two ways, beside each product’s number of observations. Green is positive, rose negative; the brighter the cell, the stronger the link. The values are generated to the study’s shape.7

Fill size per order against leg volume, by product

Busier legs go with bigger spread fills in two products, weakly in two, and not at all in the last two, including the product with the most observations.

Show the dataHide the data
Data: Fill size per order against leg volume, by product
Product (observations)PearsonSpearman
Product A (25)0.470.46
Product B (29)0.430.44
Product C (37)0.220.22
Product D (55)0.200.20
Product E (88)−0.020.05
Product F (16)−0.070.06
All products (252)0.170.17
Synthetic data. Illustrative values for 252 day-by-spread observations, generated to show the study’s shape. Pearson uses the raw values; Spearman uses ranks, so a few very large days cannot drive it. Product G, with two observations, has no coefficient. Same-day association, not a causal estimate. The method is as built; the desk’s own figures are confidential.3

04Functions

Four steps, twenty minutes.

The study has no interface. These are its steps in the order they ran on the afternoon of August 6, 2026.

A

Freeze the inputs

Before any analysis, the raw exports were frozen in a dated run folder, so every number can be re-derived.

  • Every daily order export and fill export in the window, kept before the export folder’s retention could remove them
  • Read as a stream in the terminal’s native GB18030 encoding, header located by column name
  • Spread orders are their own rows, coded by their two legs, so no leg reconstruction is needed

B

One pull, everything in it

A one-click, read-only package pulls everything the study needs from the market-data database in a single run.

  • Five read-only queries: coverage check, daily volume of every contract, the exchange’s designated market-maker contract lists for each month, spread instruments’ own rows, settlement fills
  • Leg products checked against the order data before the pull, so it could not come back short
  • Password typed at run time, never stored; the run returned an empty error file

C

Build, then prove

Two variables per day and spread, and a reconciliation that must pass before any coefficient is trusted.

  • X: filled spread lots per spread order with a fill. Y: the two legs’ combined market volume that day
  • Order-side spread lots equal the fill export’s exchange-derived leg fills ÷ 2 on every day4
  • Day-by-spread rows with orders but no fill are excluded, so every observation is a spread that traded8

D

Read the answer

One picture the desk can forward: both estimators, every product, the sample behind each, and the definitions underneath.

  • Pearson and Spearman side by side, because trading volumes are heavy-tailed
  • Per product first; the pooled row is a summary, not the result
  • Definitions and the sample size printed on the graphic itself
A results table in English, on synthetic data, with one row per product, Product A to Product G, and a pooled row. Columns give the number of observations, then the Pearson and Spearman correlations between fill size per order and leg volume. Product A reads 0.47 and 0.46 on 25 observations, Product B 0.43 and 0.44; Product E, the largest sample with 88 observations, reads minus 0.02 and 0.05; Product G has no coefficient; the pooled row reads 0.17 and 0.17 on 252 observations. Definitions are printed under the table. Enlarge
Synthetic data. The results graphic, redrawn in English on generated values: one row per product, both estimators side by side, the sample behind each, the definitions underneath. Look at marker 3 against marker 2: the product with the most observations sits near zero on both estimators, while the strongest product clears 0.4 on both.
  1. Marker 1: Column heads. Product and its number of observations, then Pearson on the raw values and Spearman on ranks, for the same pair of variables.
  2. Marker 2: Product A. Busier legs go with bigger spread fills on both estimators.
  3. Marker 3: Product E, 88 observations. The largest sample by far, with both estimators near zero and of opposite sign: the rule does not hold here.
  4. Marker 4: Pooled. A modest positive number that hides both the products where the rule holds and the ones where it does not.
  5. Marker 5: Definitions. The formula for each variable, the rule for a dash, and the finding that spread contracts show no volume of their own.

05Under the hood

For the technical reader: the model, the math and the code.

Under the hoodVariable definitions, estimators, reconciliation, pseudo-code and an illustrative coefficient table

An empirical study run to research standards under desk constraints, as a five-script data pipeline: extract, pull, parse, join and estimate, validate. The substance is the measurement design, an exact two-source reconciliation, robust and non-robust estimators reported together, fail-loud data checks, and a plain statement of what a short-window, same-day correlation can and cannot support. No model is trained; the skill on show is getting a number that can be trusted out of raw production exports and a production database, in minutes. Everything runs on standard-library Python, with nothing to install.

Two variables per day and spread

The unit of observation is a traded spread on a trading day: hundreds of them, across the desk’s Dalian products.8 For spread s with legs a and b on day d, let Lds be the desk’s filled spread lots, Nds the number of its spread orders that received any fill, and Vda the exchange-wide volume of a leg.

  • X is fill size per order. The denominator is orders with a fill, not orders sent, so unfilled quotes do not dilute it.
  • Y is leg liquidity, measured the same day.

The hypothesis, product by product, is a positive corr(X, Y).

Xds=LdsNds,Yds=Vda+Vdb
Defined only where the spread traded that day (L > 0).
Pseudo-code
for (day, spread), (lots, orders_filled) in base_table.items():   # traded spreads only
    near, far = legs_of(spread)              # a spread code names its two legs
    leg_volume = [volume.get((day, leg)) for leg in (near, far)]
    if None in leg_volume:
        missing.append((day, spread))        # recorded, never skipped silently
        continue
    x = lots / orders_filled                 # fill size per order with a fill
    y = leg_volume[0] + leg_volume[1]        # the two legs' market volume
    observations[product_of(spread)].append((x, y))

require(not missing)                         # every observation has its Y
Pseudo-code. How one observation is built, simplified: the two variables per spread and day, and a fail-loud check that every traded spread found its leg volumes.

Two estimators, written by hand

Daily volumes are heavy-tailed, so a handful of very large days can carry a Pearson coefficient. Each correlation is therefore reported twice: Pearson on the raw values, and Spearman, which is Pearson on tie-averaged ranks and responds only to ordering. Where the two disagree in sign or size, the reading is that no stable relationship exists.

Both are implemented directly from their definitions. A group with fewer than three points or zero variance returns no coefficient, and the table shows a dash.

Rejected: a pooled coefficient as the headline. Products differ in volume by an order of magnitude, so a pooled number mixes level differences between products with co-movement within them. The per-product rows are the result.

Rejected: a correlation against the spread contract’s own volume. It was planned and computed, and came back undefined: the exchange books spread trades entirely to the legs, so that field is zero on every row pulled.5

r=∑i(ai−a¯)(bi−b¯)∑i(ai−a¯)2∑i(bi−b¯)2,ρ=r(rank a, rank b)
Pearson’s r, and Spearman’s ρ as Pearson on ranks, with tied values given the average of the ranks they span.
Pseudo-code
def pearson(a, b):
    if len(a) < 3:
        return None                      # too few points: a dash in the table
    da = [v - mean(a) for v in a]
    db = [v - mean(b) for v in b]
    if norm(da) == 0 or norm(db) == 0:
        return None                      # no variance: no coefficient
    return dot(da, db) / (norm(da) * norm(db))

def ranks(a):
    order = positions of a, sorted by value
    for each run of tied values at sorted places i..j:
        every member gets rank (i + j) / 2 + 1   # the average of the ranks it spans
    return the ranks, in the original order

def spearman(a, b):
    return pearson(ranks(a), ranks(b))
Pseudo-code. Both estimators from their definitions, simplified. Standard-library Python only: no pandas, NumPy or SciPy.

Results

Order size against leg liquidity turned out to be product-specific: clear in two products, moderate in two, and absent in two, where Pearson and Spearman did not even agree on sign. The product with the most observations was among the last two, so “liquid legs suit bigger spread orders” is a sound rule only where its own product’s coefficients say so, and a pooled coefficient would have hidden both answers. The table shows that shape on generated values.7

Synthetic data. Illustrative values, generated to the study’s shape. Rows in descending order of the Pearson coefficient; a dash where a product has fewer than three observations. The method is as built; the desk’s own figures are confidential.
ProductnPearsonSpearman
Product A250.470.46
Product B290.430.44
Product C370.220.22
Product D550.200.20
Product E88−0.020.05
Product F16−0.070.06
Product G2––
Pooled2520.170.17

Validation: two files, one truth

The base table comes from the order export. The check comes from the fill export, a separate file in which the exchange’s derived leg trades of spread orders carry their own trade type. Each filled spread lot produces exactly two such leg lots, so for every day the two totals must satisfy the identity below. It held on every day of the window, to the lot.4

Further guards, all fail-loud:

  • Coverage before the pull. The SQL asked for a deliberate superset of products, and the leg products extracted from the orders were checked against it before the pull ran, so no observation could lack its Y.
  • No silent gaps in the join. A spread-day whose leg volume is missing aborts the run; an unparsable contract code aborts the extraction.
  • Empty error file. The database run was checked for errors before its results were used.
  • Second cross-check. One day’s total was also matched to the Spread Calculator’s own spread summary.
∑sLdsorders=12∑f∈Fdqffor every trading day d
Left: filled spread lots from the order export. Right: F is the set of exchange-derived leg fills in the fill export, q their lots.
Pseudo-code
spread_lots = per_day_sum(base_table, "filled spread lots")    # order side

all_days_match = True
for day in window:
    leg_lots = 0
    for row in stream(fill_export(day)):       # columns found by header name
        if row.trade_type == LEG_DERIVED_FROM_SPREAD:
            leg_lots += row.lots
    match = (leg_lots == 2 * spread_lots[day])  # integer equality, no tolerance
    all_days_match = all_days_match and match
Pseudo-code. The reconciliation, simplified: every filled spread lot must appear as exactly two exchange-derived leg lots in the separate fill record. The test is integer equality, with no tolerance.

Twenty minutes, by the clock

The speed came from sequencing, and from infrastructure already in place. Everything that did not need the database was finished before the pull: the raw exports frozen, the base table built, the leg products enumerated and checked against the superset the SQL requested. The pull itself was one click, and the estimation, the reconciliation and the write-up ran as soon as the results file was back.

Three earlier builds of Shuo’s made that possible: the order exports already feeding his Spread Calculator, his own reference map of the production database, and his one-click, read-only SQL template.

Beijing time, from the work log’s own timestamps.
Clock, Aug 6, 2026Event
16:59:00Request: the colleague’s specification, with Shuo’s data plan and window
17:09:16Raw exports frozen, base table built, one-click SQL package ready
17:13Clean database run, empty error file
17:15:11Results file back for analysis
17:19:16Per-product correlations delivered with the reconciliation: 20 min 16 s
17:30:14Forwardable results graphic rendered

Questions a quant will ask

The obvious challenges, answered. None of them was run as an extra test in the delivered study; they bound how far its result can be pushed.

  • Is X the market’s capacity or the desk’s choice? Partly the desk’s choice. Fill size per order cannot exceed the size sent, so corr(X, Y) can also reflect a sizing habit that already sent bigger orders when the legs were liquid. The study measures association in realized trading. It does not identify what a larger order, or an untried spread, would have filled.
  • Is Y partly the desk’s own trading? Slightly. Spread trades are booked to the legs, so the desk’s own spread lots sit inside Y. The overlap was not netted out; it can only push corr(X, Y) upward, so it cannot explain away the products where the rule fails.
  • Are the strong coefficients distinguishable from zero? Naively, yes: the textbook t-statistic, rn−2/1−r2, clears 2 for the two strongest products and not for the two where the rule fails. It treats observations as independent, though, and the same spread recurs across the window’s days, so it overstates confidence. No significance test was reported to the desk.
  • Why same-day volume? That was the specification. A desk choosing tomorrow’s spreads would want yesterday’s leg volume as the predictor. That variant is the natural next step.
  • Data timing. Daily volumes come from the last snapshot recorded before the close, so the final minutes are missing uniformly across contracts, which is harmless for a correlation.
  • Why not log-transform the volumes? Spearman is invariant to any monotone transform, so the rank column already is the log-log answer. Pearson on raw values sits beside it to show what the heavy tail does.
  • Why not one regression with product dummies? The desk’s question was which products the rule holds for. Per-product coefficients answer it directly and let the relationship differ by product; a pooled slope with fixed effects would average a product where the rule holds and one where it fails into one number that describes neither.

Built with

  • Python (standard library)
  • SQL
  • MariaDB
  • Data pipeline (extract, join, validate)
  • Empirical research design
  • Fail-loud assertions
  • Pearson and Spearman correlation
  • Rank statistics
  • Data reconciliation
  • Stream parsing (GB18030 CSV)
  • Windows batch
  • Reproducible data pulls
  • Market microstructure

06Releases

Shipped in versions, like a product.

  1. Study deliveredRequest at 16:59, verified correlations at 17:19, results graphic at 17:30. One-shot study; no later versions.
  2. ReusedThe study’s pull of the exchange’s designated market-maker contract lists verified the list built into the self-trade checker: a match for all ten products.
  1. 1A colleague proposed the question and the variables to measure. Shuo fixed the remaining definitions, among them the denominator of fill size per order (orders with a fill, not orders sent), and printed them on the delivered graphic.
  2. 220 minutes 16 seconds from the request (16:59:00) to delivery of the per-product correlations with the reconciliation (17:19:16) on Aug 6, 2026, Beijing time, including the database pull. The forwardable graphic followed at 17:30:14, 31 minutes after the request.
  3. 3Pearson and Spearman correlations between filled lots per filled spread order and the two legs’ combined market volume on the same day, computed per product. Same-day association over a short window, not a causal estimate; most per-product samples are small, so a strong coefficient is a clear signal, not a precise one. The chart, the table and the redrawn graphic show generated values with the study’s shape.
  4. 4On every day of the window, filled spread lots summed from the order export equal the exchange-derived leg fills in the separate fill export divided by two, exactly. Lot totals are confidential and not shown.
  5. 5Every daily row pulled for the exchange’s listed spread contracts over the window reports zero volume of its own: the exchange books spread trades to the two legs.
  6. 6Aug 10, 2026: the exchange’s designated-contract lists pulled for this study were compared with the list the self-trade checker used for July 2026 and matched for all ten of the desk’s market-making products.
  7. 7Charts, figure data and screenshots on this page are synthetic, illustrative or public market data. Methods and outcomes are described as they happened; the desk’s own figures are confidential and do not appear here.
  8. 8The window was the longest recent stretch in which the desk’s spread orders were comparable from day to day. Day-by-spread rows with orders but no fill are excluded, so every observation is a spread that traded that day. Sample sizes, like the coefficients, are confidential; the counts shown on this page are generated.
Previous
Previous

Desk Reference Cards

Next
Next

USB Switch Fixer