Rolling Five Minute VWAP Over a Stream of Trades
Last updated: November 29, 2026
Quick Overview
Given trades arriving in time order as (timestamp_seconds, price, quantity), output after each trade the volume-weighted average price of all trades in the trailing five minute window.
Balyasny
November 29, 20260
0
0 solved
Given trades arriving in time order as (timestamp_seconds, price, quantity), output after each trade the volume-weighted average price of all trades in the trailing five minute window.
VWAP is the benchmark most execution algorithms and PMs at Balyasny use to judge fill quality, and streaming windowed aggregates appear throughout its market data tooling. The interviewer wants a constant-time per-trade update and precise window boundaries.
What the Interviewer Expects
- Use a deque plus running sums instead of re-summing the window
- State whether the window is open or closed at the left edge
- Handle zero total volume without dividing by zero
- Give O(1) amortized per-trade cost
- Mention numerical drift in long-running float sums
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support many symbols at once?
- What changes if trades can arrive slightly out of order?
- How would you compute a time-weighted average mid price instead?
- How do you avoid float drift over a full trading day?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is non-decreasing timestamps. The window for a trade at time t covers trades with timestamp greater than t - 300, so a trade exactly 300 seconds old is excluded. Output (t, vwap) after eac...
High-Level Design
Maintain a deque of trades in the window and two running totals: sum of price times quantity and sum of quantity. On each trade, append and add, then pop from the left while the oldest trade is out of...