Software · Desk tool
Position Atlas 持仓量统计
Proposed and shipped within his first nine days: the program that tells a market-making desk, every evening, exactly how much position the exchange counts and how much it must hold from here.
01System architecture
Two independent records of the desk’s trades, one ledger, and the exchange’s own numbers as the referee.
The desk’s PCs are standard-user machines with nothing installed. So Position Atlas ships as one code-signed, self-updating executable that runs offline on the trader’s own PC, reads files the desk already receives, and updates itself from the shared drive.
Read-only network folder
Daily settlement statements
The broker’s end-of-day record: long, short and margin per contract, plus every trade with its exchange trade number.
Watched folders
Same-day trade exports
Tonight’s trades before the statement lands, with trade time, order type and order reference.
Reconciliation module
Self-trade ledger
Pairs trades by trade number, classifies each pair, applies each exchange’s rule, cross-checks both sources.
Exchange reports
The exchanges’ obligation reports
The Shanghai exchanges’ own daily figure per contract. Every contract-day is compared.
The trader’s own PC, offline
Position Atlas
Effective open interest, month average, completion, average still needed, raw position to hold.
Desk shared drive
Signed releases · shared configs · logs
Updates pass a pinned-signature gate and a health window; a failing build reverts itself.
Local browser window
Trader
Reads the forecast, confirms listing days, opens the evidence behind any deduction, exports the month to Excel.
Simplified: the statement parser, the per-day cache and the Excel and CSV exporters live inside the Position Atlas node.
Why two sources for the same trades?
The statement is authoritative but arrives after the close. The trade export is available the same evening, including the night session. On any day both are complete, every per-contract count must agree; a difference raises an alert and the statement wins.
Why does the exchange get the last word?
The written rule can be read three ways. Only the exchange’s own figure says which reading it applies, so the app compares every contract-day and flags any mismatch in red.
Why a local, offline app?
It needs no server, and the data stays where it already is. The program serves only its own machine; the browser is just the window.
02The story
2,410 of 2,410 contract-days matched the exchanges’ own obligation reports. Version 1.0 shipped on his ninth day.
An exchange expects each of its designated market makers to hold a minimum position in its assigned contracts, on average over the month. The desk tracked that in a spreadsheet. Within days of joining, Shuo offered to automate it; on his ninth day he shipped it. Today Position Atlas reads the broker’s statements itself, applies each exchange’s fine print, and gives a trader the one number that matters: the average still needed on each remaining day. Its figures matched the exchanges’ own obligation reports on 2,410 of 2,410 contract-days.1
01
The problem
Think of a bank that sets a minimum average daily balance for the month. Hold too little and you fall short of its terms. Hold too much and your money sits idle. Now add a twist: the bank quietly ignores any deposit you made by moving money between your own pockets.
That is a market maker’s open-interest obligation. A market maker is a firm the exchange appoints to keep buy and sell prices on the screen all day; open interest is the position it still holds at each day’s close. Each month the exchange sets a minimum average position (long plus short, taken at each day’s close) for the market maker’s assigned contracts, and the open interest that counts feeds the exchange’s evaluation of its market makers. Positions created when the desk’s own buy order meets its own sell order do not count. On a market-making desk these are unintended matches, typically a spread order’s exchange-derived leg meeting one of the desk’s own quotes.
- The trading terminal shows no month-to-date average, so the figure has to be built from each day’s statement. The desk tracked it in a spreadsheet.
- Hand-keyed figures invite typos, and a spreadsheet
AVERAGEskips blank cells while the exchange counts a missing contract as zero, so the two can disagree in the direction that makes a missed target look met. - The exchange’s deduction for self-trades was one sentence in its market-making rules, open to three readings.
02
What he built
During his desk training Shuo saw the evening routine of keying statement figures into the spreadsheet, and proposed on the spot to write a program that reads the statements itself. Nobody assigned it. Version 1.0 shipped eight days after he started, and it reproduced the hand-kept sheet on all 15 contracts.2,3
He conceived it, designed it and built every part of it himself: the parser, the forecast, the deduction rules, the tests and the delivery. Position Atlas now does the whole job:
- Reads each day’s settlement statement within minutes of its arrival and computes every contract’s position, month average and completion.
- Forecasts the average still needed on each remaining trading day, under the calendar each exchange actually uses.
- Deducts self-trades under each exchange’s own rule,4 and shows the evidence for every deduction down to the trade number.
- Proves itself daily against the Shanghai exchanges’ own obligation reports.
- Ships as one signed executable, built for every trader on the desk, that updates itself from the shared drive.
03
Why “average still needed” is the number
Holding a huge position all month would meet any target, and would be the wrong answer three times over.
- Every lot costs capital. The obligation is held as matched long and short positions, and each lot ties up margin for as long as it is held.
- The exchange caps positions. Position limits bound how much can be held, and they step down as a contract nears delivery, exactly when a late catch-up would be needed.
- It is an average of daily closes. A position built early counts on every later day; a spike during the day counts for nothing.
So the efficient path is to build early, then hold exactly what the average still requires. Position Atlas computes that figure for every contract, every evening, and a scenario calculator answers the awkward follow-up: if a limit caps the last days of the month, what must be held on the days before?
04
What changed
- The evening spreadsheet is automated. The month’s table still exports to Excel in the old layout, with live formulas, for anyone who wants it.
- An ambiguous rule became a verified one. A colleague asked whether the Shanghai deduction rule could be programmed. Shuo tested three readings of its wording against the exchanges’ own obligation reports; one matched on 2,410 of 2,410 contract-days, and the other two failed.1 That reading shipped.
- Mistakes in either direction became visible. A newly listed contract read far less complete than it was, which could push a trader to over-hold. Shuo traced it to the days before the contract existed and added a listing-day rule the same day.5
- One tool for the whole desk. One signed file on the shared drive that every trader’s PC can reach: 21 releases from v1.0 to v4.1.1, and since v3.0.0 every update signature-checked and reversible.
- It runs every trading day. Each new statement is parsed within minutes of arriving, and Position Atlas is one of the four desk tools built into The One, Shuo’s single-window hub.
2,410/ 2,410
contract-days where its number matched the exchanges’ own obligation reports. Zero misses.1
8days
from his first day on the desk to a shipped version 1.02
15/ 15
contracts identical to the desk’s hand-kept spreadsheet in version 1.0’s first check3
489
daily settlement statements rebuilt into one self-trade ledger: two years of trades, zero errors6
129
automated regression tests guarding about 11,000 lines of code across Python, the web interface and the C# launcher7
03Evidence
Three readings of one rule. One matches the exchange every time.
The exchange’s deduction rule can be read three ways. Shuo scored each reading against the Shanghai exchanges’ own obligation reports: the reading he shipped matched 2,410 of 2,410 contract-days, and the other two failed. The chart replays that test on a synthetic set.
Contract-days wrong in a synthetic replay of the test: three readings of the rule and two baselines
Only the shipped reading matches on all 1,680 synthetic contract-days; the literal text gets 71 wrong.
Show the dataHide the data
| Reading of the rule, or baseline | Contract-days wrong, of 1,680 |
|---|---|
| Both opened, 2 × lots (shipped) | 0 |
| Both opened, 1 × lots | 63 |
| No deduction (baseline) | 63 |
| Every opening side (literal) | 71 |
| Every self-trade, 2 × lots (baseline) | 75 |
04Functions
Everything it does, in the order a user meets it.
A
Overview
The month at a glance: how far along it is, which targets are on track, and every day’s position per contract in the layout of the old hand-kept sheet.
- A new statement is parsed within minutes of landing in the folder; a per-day cache makes every later load instant
- One switch flips the whole page between raw positions and what the exchange counts
- Shanghai contracts show their own assessment month, offset from Dalian’s calendar month, in the same grid
Enlarge
- Marker 1: Trading-day progress (top left): 10 of the calendar month’s 22 trading days done, 12 left. The Dalian forecasts count down from here.
- Marker 2: On track: 11 of the 12 contracts that carry a target are secure or need only holding.
- Marker 3: Effective / raw switch: shows positions as the exchange counts them, or as plain long plus short.
- Marker 4: Struck-through rows: the first three days belong to the Shanghai assessment month only, so Dalian contracts are crossed out for those days.
- Marker 5: Shanghai contracts on the same rows stay live: their assessment month opens before the calendar month. Section C shows this corner up close.
- Marker 6: Dotted cells carry a self-trade deduction; in the app, hovering shows raw minus deduction, the source and the exchange check.
B
Targets and forecast
One row per contract: the exchange’s minimum, where the month stands, and the average needed on each remaining trading day.
- Plain statuses (secure, just maintain, add, big gap; met or missed once the period ends), so a trader sees at once which contracts need attention
- A permanent library of targets: un-watching a contract never loses its requirement
- A position-limit scenario on every row that is not yet secure
Enlarge
- Marker 1: Target, then the average so far (first two number columns): the exchange’s monthly minimum and where this contract stands.
- Marker 2: Completion: 80%, in red, means this contract’s average so far is below its monthly minimum.
- Marker 3: Average still needed: the position to hold on each remaining day to finish the month at the target, here 410 lots against 273 held. This is the number traders act on.
- Marker 4: Trend: the month’s daily positions against the dotted target line.
- Marker 5: Status chip (here “just maintain”) and, beside it, the button that opens the position-limit scenario.
- Marker 6: Watch-only contracts have no target but are still tracked: this one’s effective position is below zero after deductions.
C
The calendar the exchanges actually use
A monthly average is only as right as its day count, so every calendar rule that changes the denominator is built in.
- Assessment month. Shanghai contracts are assessed over a month offset from the calendar month; Dalian contracts use the calendar month. Holidays are built in; future days can be switched off by hand.
- Listing day. A contract that lists mid-month is assessed from its listing day. The app detects it and asks the trader to confirm before changing anything.5
- Position-limit scenario. If a limit cut caps the last few days of the month, the calculator shows the average needed on the free days before it and whether today’s position would still pass.
Trading days counted toward Month 2 under each calendar
Shanghai’s assessment month opens before the calendar month and closes before it ends: in this illustration it counts 21 trading days, Dalian’s calendar month 22, and only 18 are the same days.
| Series | Trading days in sequence, illustrative calendar | Trading days counted |
|---|---|---|
| Shanghai | 0.5 | 0 |
| Shanghai | 1.0 | 1 |
| Shanghai | 2.0 | 2 |
| Shanghai | 3.0 | 3 |
| Shanghai | 4.0 | 4 |
| Shanghai | 5.0 | 5 |
| Shanghai | 6.0 | 6 |
| Shanghai | 7.0 | 7 |
| Shanghai | 8.0 | 8 |
| Shanghai | 9.0 | 9 |
| Shanghai | 10.0 | 10 |
| Shanghai | 11.0 | 11 |
| Shanghai | 12.0 | 12 |
| Shanghai | 13.0 | 13 |
| Shanghai | 14.0 | 14 |
| Shanghai | 15.0 | 15 |
| Shanghai | 16.0 | 16 |
| Shanghai | 17.0 | 17 |
| Shanghai | 18.0 | 18 |
| Shanghai | 19.0 | 19 |
| Shanghai | 20.0 | 20 |
| Shanghai | 21.0 | 21 |
| Shanghai | 21.5 | 21 |
| Dalian | 0.5 | 0 |
| Dalian | 4.0 | 1 |
| Dalian | 5.0 | 2 |
| Dalian | 6.0 | 3 |
| Dalian | 7.0 | 4 |
| Dalian | 8.0 | 5 |
| Dalian | 9.0 | 6 |
| Dalian | 10.0 | 7 |
| Dalian | 11.0 | 8 |
| Dalian | 12.0 | 9 |
| Dalian | 13.0 | 10 |
| Dalian | 14.0 | 11 |
| Dalian | 15.0 | 12 |
| Dalian | 16.0 | 13 |
| Dalian | 17.0 | 14 |
| Dalian | 18.0 | 15 |
| Dalian | 19.0 | 16 |
| Dalian | 20.0 | 17 |
| Dalian | 21.0 | 18 |
| Dalian | 22.0 | 19 |
| Dalian | 23.0 | 20 |
| Dalian | 24.0 | 21 |
| Dalian | 25.0 | 22 |
| Dalian | 25.5 | 22 |
Enlarge
- Marker 1: First row, still in Month 1: the Shanghai exchanges’ assessment month opens here.
- Marker 2: Struck through: Dalian contracts do not count on these three days. Their month is the calendar month.
- Marker 3: Live: the Shanghai contracts on the same rows already count toward the new month.
- Marker 4: The 1st: the first trading day of Dalian’s month. From this row down, every column counts.
D
What the exchange counts
Effective open interest: long plus short, minus the positions the desk created by trading with itself, under each exchange’s own rule.
- Shanghai: twice the lots of every self-trade in which both sides opened, deducted on that day and every later day of the contract
- Raw position to hold: the average still needed, grossed up for deductions that keep running, so the effective number still clears the target
- Missing trade data is never silently treated as zero: an unparsed day shows as pending and totals show as lower bounds
Enlarge
- Marker 1: Exchange tag beside each contract: Dalian rows above, Shanghai rows from here down. Each exchange has its own rule.
- Marker 2: Deducted column: zero for these Dalian contracts this month.
- Marker 3: 8 lots: the running total of earlier self-trades in which both sides opened, now taken off this Shanghai contract’s count every day.
- Marker 4: Raw to hold, 10: the 2 lots a day still needed plus the 8-lot deduction that keeps running.
- Marker 5: Effective position −4: the deduction now exceeds the position held. The rule has no floor at zero, and the app reproduces that.
- Marker 6: Data check (far right): every trading day of the period has complete trade data behind it.
E
Evidence for every deduction
Any day in the ledger opens to the individual self-trades behind it, from two independent sources that must agree.
- Each pair is classified by what its two sides did: both opened, one opened and one closed, or both closed
- The trade export adds the time, the order type and, on request, both orders’ references
- Coverage bars and an exchange check show at a glance that nothing is missing and everything matches
Enlarge
- Marker 1: Green banner: the two data sources agree on this day, contract by contract.
- Marker 2: The deduction: 4 lots where both sides opened, times 2, equals 8 lots off the exchange’s count.
- Marker 3: Opening-side lots, 14: what the most literal reading of the rule would deduct. The reading that shipped deducts 8.
- Marker 4: Both sides opened (red): the desk’s buy met its own sell and created a long and a short. These are the only pairs the exchange deducts.
- Marker 5: Mixed pair (amber): one side opened, the other closed. Net position unchanged, so nothing is deducted.
- Marker 6: Both sides closed: a pair that removes positions and is never deducted.
Enlarge
F
Export, share, update
Built for every trader on the desk: one file to copy and run.
- Exports. The month in the old spreadsheet’s layout with live formulas; the effective workbook adds raw positions, deductions with the exchange’s own value, and the method
- Shared targets. Readable one-line-per-contract files in monthly shared folders, numbered so the latest is obvious; imports are previewed, merged, backed up and read back
- Updates and logs. One click checks the shared drive, verifies the signature, restarts on the new build and reverts if it fails; logs export to the shared drive daily
05How it works
What the exchange counts, and how the rule was proved
Effective open interest, day by day
Synthetic data. The ten-day ledger, the 40-lot minimum and the three-readings replay are illustrative, generated to show the effect. The rule is as built: effective = long + short − 2 × lots of every self-trade in which both sides opened, carried for the life of the contract. On the exchanges’ own obligation reports that rule matched 2,410 of 2,410 contract-days; the desk’s own figures are confidential.
Text description of this figure
The figure walks through one contract over a short illustrative month in four panels. Panel 1, the ledger: each day’s long and short positions and their sum, with a marker on days when the desk traded with itself. Panel 2, the exchange’s rule: effective equals long plus short minus the sum of 2q, where q is the lots of every self-trade so far in which both sides opened. A self-trade where both sides open adds 2q to the running deduction; a pair where one side opens and the other closes adds nothing. On the Shanghai exchanges the deduction is carried on every later day of the contract and never floored at zero; for Dalian it is modeled as deducted once, on the day, and labeled presumed. Panel 3, what the exchange counts: daily bars split into the part that counts and the part deducted, with the plain average and the effective average shown against the minimum. Holding the usual position for the rest of the month ends with a plain average of 45.0 and an effective average of 39.2, below the 40-lot minimum; holding the raw-to-hold figure that Position Atlas computes (46.7 lots a day, so 48) finishes the month at 40.4. Panel 4, the proof: checked against the exchanges’ own obligation reports, the shipped reading matched 2,410 of 2,410 contract-days. Beside it, three readings of the same written rule are replayed on a synthetic test set of 1,680 contract-days: both sides opened at 2 × lots matches all of them; both sides opened at 1 × lots misses 63; every opening side misses 71.
06All screens
Six views of the program.
07Under the hood
For the technical reader: the model, the math and the code.
Under the hoodModels, math and code for the technical reader
For the quant and the engineer: the obligation arithmetic, an ambiguous exchange rule treated as a hypothesis and tested against ground-truth data, the reconciliation logic, the data pipeline with its cross-checks, and how an obligation-critical number is shipped as one signed executable with signature-gated updates and automatic rollback. Shuo designed and built all of it: about 11,000 lines across a Python 3.10 and Flask application, a framework-free JavaScript interface and a C# self-extracting launcher, guarded by 129 regression tests, plus the PowerShell scripts that build, sign and publish it.7
The obligation as arithmetic
For contract , each counted day’s open interest is long plus short from that day’s statement. A contract absent from a statement counts as zero, which is the exchange’s arithmetic (sum over trading days); a spreadsheet AVERAGE that skips blanks reads higher and can show a missed target as met.
With target , counted days so far, accumulated open interest and trading days remaining in the contract’s assessment window, the average still needed is the display formula below. The window is the calendar month for Dalian and, for the Shanghai exchanges, an assessment month offset from the calendar month; excludes built-in holidays and manual closures; and for a contract listed mid-month the first days are dropped from and once the trader confirms the detected listing day.
Position-limit scenario. If the last of the remaining days are capped at lots, the need on the free days becomes . A cap on the final days can silently break a plan that looked like “just maintain”.
Worked example (illustrative numbers). Target 3,000 lots over a 21-day month; 7 days counted at an average of 2,700, so and . The average still needed is (63,000 − 18,900) / 14 = 3,150 lots a day. If a limit caps the last 2 days at 1,200 lots, the 12 free days must carry (63,000 − 18,900 − 2,400) / 12 = 3,475. A trader holding 3,200 believes the month is safe and misses it.
The same formulas exist twice, in the server (used by exports) and in the page, and a parity test holds them equal. The calculation functions are pinned by a “business lock” test that fails on any change until it is deliberately re-pinned.
# one contract, inside its assessment window
counted = daily_open_interest[listing_skip:] # long + short on each counted day
total = sum(counted)
average = total / len(counted) if counted else 0
days_left = len(remaining_trading_days)
still_needed = None
if days_left and target:
still_needed = max(0, (target * (len(counted) + days_left) - total) / days_left)Effective open interest: the rule as a hypothesis
A self-trade is one exchange trade number that appears twice in the desk’s own account on the same exchange and trading day, once as a buy and once as a sell: both sides of the match were the desk. What it does to positions depends on each side’s open or close flag.
- Both sides open: long +q and short +q, so long + short rises by 2q.
- One opens, one closes: +q on one side, −q on the other. No change.
- Both close: long + short falls by 2q.
The Shanghai exchanges’ market-making rules treat open interest created by self-trades as invalid and deduct it on the day and on every later day. That sentence supports at least three implementations: deduct 2q for both-open pairs; deduct q for both-open pairs; or deduct q for every opening side, which also charges mixed pairs. Position Atlas makes the choice a per-exchange setting, so the question can be put to data rather than argued.
The shipped rule for the Shanghai Futures Exchange and the Shanghai International Energy Exchange is the display formula: a lifecycle deduction that accumulates from the first statement on file, includes an opening balance for anything earlier, and is never floored at zero, because the exchange does not floor its own figure.
Because the deduction keeps running, the position a trader must actually hold is higher than the effective need: raw to hold = , where the effective need is taken before its floor at zero and is the deduction that will apply on each remaining day, including self-trades booked since the last statement.
def deduction(day_totals, reading):
both_open = day_totals.both_open_lots # lots of pairs in which both sides opened
if reading == "one_times":
return both_open
if reading == "two_times": # the reading that shipped
return 2 * both_open
return day_totals.opening_side_lots # the literal text: every opening side| Exchange | Rule | Deducted | Status |
|---|---|---|---|
| Shanghai Futures Exchange | Lifecycle | 2q per both-open pair, on that day and every later day; never floored | Verified against the exchange’s own daily figures, including every contract-day that carried a deduction |
| Shanghai International Energy Exchange | Lifecycle | Same | Matches every contract-day in the exchange’s own reports |
| Dalian Commodity Exchange | Month | 2q per both-open pair, once, on the day | Presumed; labeled as such in the app4 |
| Zhengzhou, Guangzhou, CFFEX | Off (default) | Nothing | Zhengzhou’s statement trade numbers lose precision, so its trades cannot be paired from statements |
The test: 2,410 contract-days against the exchange
The Shanghai exchanges report to each market maker its daily effective open interest per contract. That is ground truth, so each reading of the rule was scored by how many reported contract-days it reproduces, to the lot. The shipped reading reproduced 2,410 of 2,410; the other two failed.1
The test is honest about its own power. Plain long + short already matches every contract-day that carries no deduction, and those are the large majority. The readings part ways only on the few contract-days that carry a self-trade with an opening side, and the shipped reading matches all of them.4 The app reruns this comparison on every new exchange file; a mismatch is a red alert that names the contract and day.
Why each rejected reading fails:
- 1 × lots under-deducts every both-open pair by half, so it is wrong on every contract-day that carries a deduction.
- Every opening side (the literal text) also charges mixed pairs, which leave long + short unchanged.
- No tolerance. Scoring is equality in whole lots. Positions are whole lots and a self-trade can be a single lot, so on a deciding contract-day two readings can differ by a lot or two; a tolerance band would blur exactly the cases that decide the rule.
The chart and the table replay the test on a synthetic set: 40 contracts over 42 trading days, 58 self-trade pairs, scored the same way. There, every reading agrees on 1,599 of the 1,680 contract-days; the 1 × reading fails on the 63 that carry a deduction, and the literal reading on 71.
While history is still being backfilled a lifecycle total is only a lower bound, so a mismatch in the one direction a lower bound can explain (the program above the exchange) is recorded as pending instead of raising a false alarm. That is the pending branch in the sketch.
Self-trade pairs in the synthetic replay, by type
Only 17 of the 58 synthetic pairs opened on both sides, the only kind the exchange deducts; the literal reading also charges the 29 mixed ones.
| Category | Self-trades (pairs) |
|---|---|
| Both opened | 17 |
| Mixed | 29 |
| Both closed | 12 |
for day in trading_days:
reported = exchange_figure(contract, day)
if reported is None:
continue # no report for this contract-day
raw = long_position(contract, day) + short_position(contract, day)
ours = raw - running_deduction(contract, day)
if ours == reported:
matched += 1
elif ours > reported and history_incomplete(contract, day):
pending += 1 # a lower bound can explain it
else:
mismatched += 1 # red alert naming contract and day| Reading of the rule, or baseline | Contract-days matched | Wrong |
|---|---|---|
| Both sides opened, 2 × lots (shipped) | 1,680 / 1,680 | 0 |
| Both sides opened, 1 × lots | 1,617 / 1,680 | 63 |
| Every opening side (the literal text) | 1,609 / 1,680 | 71 |
| Every self-trade, 2 × lots (baseline) | 1,605 / 1,680 | 75 |
| No deduction, plain long + short (baseline) | 1,617 / 1,680 | 63 |
Pairing and classification: the logic
The pairing is strict by design. Two rows that share a trade number must mirror each other exactly (contract, lots, price, time, one buy and one sell); anything else is returned as a problem and the day is flagged as a data error instead of being counted. For a number that feeds an exchange obligation, a loud failure is better than a plausible wrong figure. The pairing rule is the one in Shuo’s Self-Trade Check inside Spread Calculator, in production since August 2026.
def match_pairs(trades):
pairs, problems = [], []
for number, rows in group_by(trades, account_and_trade_number):
if len(rows) == 1:
continue # an ordinary trade
if len(rows) != 2:
problems.append((number, "appears more than twice"))
continue
a, b = rows
if {a.side, b.side} != {BUY, SELL}:
problems.append((number, "not one buy and one sell"))
continue
if (a.contract, a.lots, a.price, a.time) != (b.contract, b.lots, b.price, b.time):
problems.append((number, "rows do not mirror"))
continue
pairs.append(Pair(buy=a if a.side == BUY else b, sell=b if a.side == BUY else a))
return pairs, problems # any problem flags the day as a data error
def classify(pair):
opening_sides = int(pair.buy.opens) + int(pair.sell.opens)
kind = {2: "both open", 1: "mixed", 0: "both close"}[opening_sides]
return kind, opening_sides, pair.buy.lotsData pipeline and its checks
- Primary source: the trade-record sheet inside the same settlement statements the app already read for positions. It covers every exchange and every trade, so the lifecycle total could be rebuilt for the whole two-year archive: 489 files, about 2 GB, parsed newest-first in resumable 45-second rounds in the background.6
- Early source: same-day trade exports in watched folders, so tonight’s night session is counted before its statement exists. Files in several folders are unioned by trade number and never double-counted; an export from a different account is refused.
- Cross-check: on any day both sources are complete, five per-contract counts (both-open pairs and lots, mixed pairs and lots, opening-side lots) must be identical. Any difference is an alert, and the statement wins.
- Trading-day logic: a night session belongs to the next trading day. This was confirmed against the exchange’s own figures on the days it mattered.
- Cache: each statement is parsed once and keyed on file time and size; the first load of a month takes about ten seconds and later loads are instant.
| Check | Result |
|---|---|
| Effective open interest vs. the exchanges’ own obligation reports | 2,410 / 2,410 contract-days |
| Settlement statements parsed into the ledger | 489 / 489, zero errors |
| Ledger from trade exports vs. the production ledger of Spread Calculator, Dalian | Identical on every trading day compared |
| Independent recount of every Shanghai self-trade pair with separate code, two trading days | Both sources agree trade for trade; the app matches on every contract |
| Definition check: long + short vs. the Dalian exchange’s own daily market-maker open interest, one month | Identical on every product-day compared |
| Version 1.0 vs. the hand-kept spreadsheet | 15 / 15 contracts identical |
| Raw-mode exports vs. the frozen v1.6 build | CSV byte-identical, workbook cell-identical |
| Python regression tests at v4.1.1 | 129 |
Shipping one signed executable to every desk PC
The delivery went through three designs: a Python program that needed Python installed (v1.0), a portable bundle carrying an official signed Python runtime (v1.1), and from v3.0.0 one self-extracting, code-signed executable.
- Update gate. The updater accepts a new build only if Windows verifies its Authenticode signature as intact, the signer’s certificate thumbprint equals the one pinned in the program, and its version resource equals its file name. The check calls
WinVerifyTrustdirectly throughctypes, with no extra dependency. - Health window and rollback. The new build is staged, started and watched; if it fails its health window the previous build is restored and the bad version is blocklisted.
- No execution from the network. The updater refuses to apply to a copy running from a network path, so the program always runs from a local folder and the share only carries files.
- Live update. A running copy moved from v3.0.0 to v3.0.1 through its own update button in 16 seconds; since v3.1.0, open windows also detect the new version and reload themselves.
- Proven in practice. Eleven signed builds were published through this path in a single day, each gated and reversible.9
- Configuration safety. Settings live outside the program folder, so upgrades never touch them. Every import is previewed, backed up, written atomically and read back.
The launcher and signature gates are reused from Shuo’s CHRONOS and Strategy series, so Position Atlas updates and reports logs the same way as his trading-machine tools.
def update_is_acceptable(new_build):
if not windows_confirms_signature_intact(new_build): # the file's bytes are as signed
return False
if signer_thumbprint(new_build) != PINNED_THUMBPRINT: # signed by the expected publisher
return False
if version_resource(new_build) != version_in_file_name(new_build):
return False
return True # then: stage, start, watch, revert on failureDesign choices an expert would question
| Question | Answer |
|---|---|
| The exchange already reports effective open interest. Why compute it? | The exchange’s figure is a record of past days, on the Shanghai exchanges only. The decision needs the forward numbers: the average still needed and the raw position to hold, including tonight’s self-trades before any statement or exchange file exists. Owning the rule is the only way to forecast with it. |
| Why pair on the trade number instead of matching time, price and size? | The trade number is the exchange’s own identifier of one match. The same number on a buy row and a sell row of one account is proof that both sides were the desk. Matching on time and price would be a guess. |
| Why exact equality instead of a tolerance? | Positions are whole lots and a self-trade can be a single lot, so on a deciding contract-day two readings can differ by a lot or two. A tolerance band would blur exactly the cases that decide the rule. |
| Why not floor effective open interest at zero? | The exchange does not floor its own figure, and a floor would fail the reconciliation wherever a deduction exceeds the position held. |
| Why does the statement win over the same-day export? | The statement is the broker’s settled record of every trade on every exchange. The export is a query run during the day and can cover only part of a session, so it is used early and then checked against the statement. |
| Why a local program on each PC instead of one shared service? | A local program needs no server, and each trader can point it at his own account folder. A signed file that updates itself from the shared drive gives central control of versions. |
| What does the proof not cover? | Dalian’s deduction basis, which the app labels presumed, and whether the Shanghai deduction carries into the next assessment period. Both limits are stated in the fine print.4 |
Failure modes engineered out
| Failure | Guard |
|---|---|
| A typo or a skipped blank makes a missed target look met | Positions are read from the statement; absent contracts count as zero, as the exchange counts them |
| A new contract’s pre-listing days drag its average down | Listing day detected and pre-filled; applied only after the trader confirms |
| The wrong reading of the deduction rule | Three readings scored against the exchanges’ own obligation reports; every new exchange file re-checks the shipped one |
| Malformed or duplicated trade rows inflate the count | Strict mirror check; the day is flagged as a data error and never silently counted |
| Missing history understates a lifecycle deduction | Totals shown as lower bounds (≥) until the backfill completes; an explainable mismatch is blue “to be checked”, not red |
| Two sources disagree | Per-contract cross-check on every complete day; alert, statement wins |
| A refactor changes the business math | Business-lock test, server and page parity test, byte-identical export test against a frozen build |
| A bad or tampered update reaches every trader | Pinned signer, version gate, health window, automatic revert and blocklist |
Built with
- Python 3.10
- Flask
- openpyxl
- Rule validation against exchange ground truth
- Excel and GB18030 CSV ingestion, resumable two-year backfill
- Windows Authenticode verification through ctypes
- JavaScript, HTML, CSS (no framework)
- C# self-extracting launcher
- PowerShell build, sign and publish
- Code-signed, self-updating executable with rollback
- Reconciliation and audit trail to the trade number
- Excel and CSV pipelines
- 129 regression tests
- Node and Playwright interface checks
08Releases
Shipped in versions, like a product.
- v1.0The whole application, built from nothing: statement parser, daily grid, targets, forecast, exports. Matched the hand-kept sheet on 15 of 15 contracts.
- v1.1Portable bundle that carries its own signed Python runtime.
- v1.2Position-limit scenario calculator, built-in holiday calendar, upgrade-safe settings.
- v1.4Listing-day rule for contracts that list mid-month.
- Target libraryTargets for every obligation-bearing Dalian product on the desk, kept in a permanent library.
- v2.0.0Effective open interest: self-trade ledger, per-exchange rules, reconciliation to the exchanges’ own obligation reports on 2,410 of 2,410 contract-days.
- v3.0.0One signed executable with self-update, rollback and log export through the shared drive.
- v3.2.0Assessment month for Shanghai contracts, offset from the calendar month.
- v4.0.0 – v4.1.1Redesigned workspace (v4.0.0), then the Position Atlas name and jade-bull icon (v4.1.0). v4.1.1 is the current release.
- 1Effective open interest computed by Position Atlas matched the obligation reports of the Shanghai Futures Exchange and the Shanghai International Energy Exchange on every one of 2,410 contract-days, scored by equality in whole lots. Two other readings of the same rule failed that test. The scope of the test and the desk’s own figures are confidential; the chart and the figure’s three-readings panel replay it on synthetic data.
- 2Shuo joined the desk on July 1, 2026. He proposed the program in a desk-training session in his first days; the version 1.0 release is dated July 9, 2026.
- 3All 15 contracts in the statement used for the first check matched the desk’s hand-kept spreadsheet, contract by contract.
- 4The readings disagree only on contract-days with a self-trade that has an opening side. For the Dalian Commodity Exchange the app deducts once, on the day of the self-trade; that basis is presumed and labeled so in the app, because Dalian’s daily figures carry no deduction to check against. Whether the Shanghai deduction carries into the following assessment period could not be observed in the test data.
- 5A contract for the same month of the following year lists mid-month, after the current year’s contract delists, and its obligation counts from the listing day. Before the fix the zero days before listing were averaged in, so a newly listed contract read far less complete than it was. Fixed in v1.4, July 28, 2026.
- 6489 of 489 daily settlement statements parsed with zero errors, covering two years of trading history.
- 7129 Python regression tests at v4.1.1 per the release record, plus browser-level interface checks. About 11,000 lines across the Python application, the web interface and the C# launcher.
- 8Charts, 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. The screens are English redraws of the app on a generated statement set.
- 9The eleven signed builds from v3.0.0 to v4.1.1 were all published to the desk’s shared drive on November 19, 2026, and each matches its archived release.