Cross-Margin Liquidation Engine yenw0d

Simulate a cross-margin derivatives engine: process trades, track account equity, and liquidate undercollateralized accounts as fast as possible.

Accounts are funded with a USD deposit and trade instruments whose prices change over time. When a price update causes an account’s equity to fall below 1% of its total position notional, the account must be liquidated.

Definitions

  • Account equity = balance + Σ(size_i * price_i) - Σ(total_paid_i)
  • Total position notional = Σ(|size_i| * price_i)
  • Total paid for instrument i = signed sum of trade_size * price_at_trade_time across all trades
  • Margin rule: liquidate if equity < total_notional / 100 after any price update

Input

One command per line on STDIN:

  • a <balance> – create account with USD balance (IDs start at 0, incrementing)
  • p <instrument_idx> <price> – set/update instrument price (0-indexed)
  • t <account_idx> <instrument_idx> <size> – trade size (signed) at current price
  • Final line: <account_idx> – query this account and terminate

Output

On each price update, liquidate all accounts violating the margin rule. For each liquidation, print:

liquidate <account_id> <equity> <position_notional>

Liquidation order: largest total position notional first, then account ID descending as tie-breaker. Liquidated accounts have their balance and positions cleared.

For the final query, print <equity> <notional> for the requested account.

Constraints

  • Accounts: <= 100,000
  • Instruments: <= 1,000
  • Price range: 100 to 1,000,000
  • Trade size range: 1 to 10,000

Example

a 100
p 0 100
t 0 0 10
p 0 90
0

Output:

liquidate 0 0 900
0 0
Back to listSep 14, 2026 10:58Victor MerckléVictor MerckléError
Source Code

Source code access is restricted. Log in to request access.

Challenge History
DateChallengerCostTypeStatus
Sep 15, 2026 22:21Josu San Martin10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 15, 2026 22:21010,785,32602,078,0002,121,728line 0: expected liquidate 9 -381267 321900 got liquidate 9 5013 708180stderr
2Sep 15, 2026 22:21016,227,03502,168,0002,121,728line 0: expected liquidate 12 -344054 298700 got liquidate 12 5425 648179stderr
3Sep 15, 2026 22:21011,369,21702,226,0002,121,728line 0: expected liquidate 8 -393424 311300 got liquidate 8 5040 709764stderr
4Sep 14, 2026 11:0380819,089,1219,271,0001,236,0002,117,632stderr
5Sep 14, 2026 11:0381219,235,9199,309,0001,250,0002,117,632stderr
6Sep 14, 2026 11:0382619,314,7649,449,0001,292,0002,117,632stderr
7Sep 14, 2026 11:0382821,413,3419,699,0001,066,0002,121,728stderr
8Sep 14, 2026 11:0384319,586,1109,765,0001,200,0002,117,632stderr
9Sep 14, 2026 11:0385019,713,7839,989,0001,067,0002,117,632stderr
10Sep 14, 2026 11:0387419,980,00310,198,0001,173,0002,117,632stderr
11Sep 14, 2026 11:0389320,171,66810,402,0001,214,0002,117,632stderr
12Sep 14, 2026 11:0393921,405,09410,877,0001,340,0002,117,632stderr