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 listMar 3, 2026 13:26NoSIMD_C#NoSIMD_C#Score: 208,689Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Feb 26, 2026 15:27185,1432,438,522,3552,393,860,00012,993,0002,347,008
2Feb 26, 2026 15:27188,9052,485,924,1262,451,767,0003,997,0002,289,664
3Feb 26, 2026 15:27192,2972,532,240,9702,483,871,00015,992,0002,342,912
4Feb 26, 2026 15:27195,6172,570,304,6962,535,024,0007,996,0002,392,064
5Feb 26, 2026 15:27200,5582,638,706,4152,596,259,00010,992,0002,289,664
6Mar 3, 2026 13:26201,7002,654,613,6202,607,108,00014,989,0002,383,872
7Mar 3, 2026 13:26208,6892,746,965,5522,699,967,00012,995,0002,416,640
8Mar 3, 2026 13:26211,2872,769,567,0422,737,735,0008,995,0002,424,832
9Feb 26, 2026 15:27219,0792,879,250,5672,837,041,00010,992,0002,342,912
10Feb 26, 2026 15:27223,8962,936,094,0522,902,646,0007,996,0002,281,472
11Feb 26, 2026 15:27226,6222,977,239,2212,936,088,0009,993,0002,396,160
12Feb 26, 2026 15:27248,5133,259,126,3103,215,675,00014,993,0002,457,600