Rolling Time-Window VWAP Over a Live Trade Stream
Last updated: November 29, 2026
Quick Overview
Build a component that ingests trades (timestamp, price, quantity) in time order and answers, at any moment, the volume-weighted average price of trades in the trailing window of W nanoseconds.
Virtu Financial
November 29, 20260
0
0 solved
Build a component that ingests trades (timestamp, price, quantity) in time order and answers, at any moment, the volume-weighted average price of trades in the trailing window of W nanoseconds.
VWAP is the benchmark many Virtu Execution Services agency algorithms and TCA reports are measured against, so a rolling version is a natural warm-up in a phone screen. The interviewer checks that you keep running sums instead of rescanning the window and that eviction is handled consistently on both writes and reads.
What the Interviewer Expects
- Use a deque plus running price-volume and volume sums for O(1) amortized updates
- Evict expired trades on both ingest and query
- Define the window boundary precisely (half-open interval)
- Return a sentinel when the window holds no volume
- Discuss floating point drift in long-running 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 avoid floating point drift after billions of trades?
- How would you support many symbols and many window lengths at once?
- What changes if trades can arrive slightly out of order?
- How would you handle trade corrections and cancels from the tape?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Trades arrive in non-decreasing timestamp order. vwap(now) returns sum(p*q)/sum(q) over trades with now - W < ts <= now, or None if no volume. Updates and queries should be O(1) amortized becaus...
High-Level Design
Keep a deque of trades currently in the window and two running totals: notional pv and volume vol. Each trade is pushed once and popped once, so total work is linear in the number of trades. Evict...