Quant Memo
Coding/●●●●●

Bucketed VWAP from a trade tape

Asked at Millennium

You're given a day's trade tape as (timestamp_seconds, price, size) tuples, sorted by time, plus a bucket width W in seconds. For each bucket [kW,(k+1)W)[kW, (k+1)W) that contains trades, compute its VWAP:

VWAP=ipiqiiqi\text{VWAP} = \frac{\sum_i p_i \, q_i}{\sum_i q_i}

trades = [(0.5, 100.0, 10), (0.9, 101.0, 30), (1.2, 102.0, 20)]
W = 1.0
-> {0: 100.75, 1: 102.0}     # bucket 0: (100*10 + 101*30) / 40

Return a dict mapping bucket index to VWAP, in one pass over the tape.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions