Skip to content
QuantReadySign In
#470easyMarket Microstructure

Order Book Imbalance

Problem

You are given a snapshot of a limit order book with NN price levels on each side. Compute three key quantities:

  1. Mid price: mid=(best_bid+best_ask)/2\text{mid} = (\text{best\_bid} + \text{best\_ask}) / 2

  2. Weighted mid price: wmid=best_bida1+best_askb1b1+a1\text{wmid} = \frac{\text{best\_bid} \cdot a_1 + \text{best\_ask} \cdot b_1}{b_1 + a_1} where b1b_1 is the bid size at the best bid and a1a_1 is the ask size at the best ask.

  3. Order book imbalance: imbalance=biaibi+ai\text{imbalance} = \frac{\sum b_i - \sum a_i}{\sum b_i + \sum a_i} summed over all NN 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

Execution limits: 2s · 256MB

Loading interactive editor…