LIVE
connecting to the live quote stream…
--:--:--UTC
mediumTrading○
#45

Order-book mid & micro-price

mediumTradingacceptance —~20 min

Implement micro_price(bid, ask, bid_size, ask_size) — the size-weighted fair value from the top of the book: (ask·bid_size + bid·ask_size) / (bid_size + ask_size). A heavy bid pushes the fair value TOWARDS the ask, because the bid is the side less likely to give way.

The mid is where the quotes are; the micro-price is where the next trade probably is. Return it rounded to 4 decimal places.

example 1
input
bid=100.0, ask=100.1, bid_size=500.0, ask_size=500.0
output
100.05
example 2
input
bid=100.0, ask=100.1, bid_size=900.0, ask_size=100.0
output
100.09
note

Nine lots bid, one offered — fair value leans towards the ask.

constraints
  • 0 < bid < ask
  • bid_size, ask_size > 0
teacher · 2 hints · the first is free
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to micro_price()
bid=100.0, ask=100.1, bid_size=500.0, ask_size=500.0
expected
100.05

the judge calls micro_price() with exactly these inputs · outputs are compared to 6 decimal places

● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice