#470easyMarket Microstructure
Order Book Imbalance
Time Limit: 2sMemory: 256MB
Problem
You are given a snapshot of a limit order book with price levels on each side. Compute three key quantities:
-
Mid price:
-
Weighted mid price: where is the bid size at the best bid and is the ask size at the best ask.
-
Order book imbalance: summed over all levels.
Input Format
A single line: best_bid best_ask bid_sizes ask_sizes where bid_sizes and ask_sizes are comma-separated lists of sizes at each price level (level 1 = best).
Output Format
A single line: mid weighted_mid imbalance, each to 4 decimal places.
Examples
Example 1
Input
100.00 100.10 200,150,100 100,80,60
Output
100.0500 100.0667 0.3043
mid=(100+100.10)/2=100.05. wmid=100*100/(200+100)+100.10*200/(200+100)=100.0667. sum_bids=450, sum_asks=240, imb=210/690=0.3043.
Example 2
Input
50.00 50.05 500,300 500,300
Output
50.0250 50.0250 0.0000
Symmetric book. mid=50.025. wmid=50.025. imb=0.0000.
Constraints
- •1 ≤ N ≤ 100 price levels
- •All sizes > 0
- •best_bid < best_ask
- •Output each value to 4 decimal places
Loading interactive editor…