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 listApr 30, 2026 11:57Victor MerckléVictor MerckléError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 4, 2026 14:17Tomislav Tunkovic10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 15:23017,392,0711,265,0006,303,0002,142,208line 0: expected liquidate 8 10430 13637568 got liquidate 3 -2294538 172159
2Sep 4, 2026 15:23017,318,7361,017,0006,600,0002,195,456line 2: expected liquidate 13 -9702 715890 got liquidate 2 35602 3889080
3Sep 4, 2026 15:23017,398,9171,051,0006,689,0002,142,208line 0: expected liquidate 9 124781 17004036 got 0 0
4Apr 30, 2026 12:002,93355,314,19628,098,00010,035,0002,527,232
5Apr 30, 2026 12:003,00947,371,67730,097,0009,029,0002,457,600
6Apr 30, 2026 12:003,07448,164,10131,976,0007,994,0002,494,464
7Apr 30, 2026 12:003,08948,451,00432,130,0008,032,0002,502,656
8Apr 30, 2026 12:003,12048,927,64933,471,0007,100,0002,433,024
9Apr 30, 2026 12:003,13648,870,84530,583,00010,194,0002,510,848
10Apr 30, 2026 12:003,15749,342,32530,036,00011,013,0002,338,816
11Apr 30, 2026 12:003,24550,300,46236,162,0006,027,0002,543,616
12Apr 30, 2026 12:003,30251,003,09936,943,0005,990,0002,355,200