Rolling VWAP over a trailing window
Given a time-sorted trade tape of (timestamp, price, size) and a window W seconds, output at each trade the VWAP of all trades whose timestamp is within the last W seconds (the half-open window ).
trades = [(0.5, 100.0, 10), (0.9, 101.0, 30), (1.2, 102.0, 20)]
W = 0.5
-> [(0.5, 100.0), (0.9, 100.75), (1.2, 101.4)] # at t=1.2 the t=0.5 print has aged out
Return a list of (timestamp, rolling VWAP), in amortized one pass.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.