Volume-weighted median price in Python
This easy coding problem tests your ability to implement a common market-microstructure calculation used by traders and quant analysts. It probes understanding of order aggregation, cumulative statistics, and careful handling of tie-breaking rules.
The core challenge is smaller than it appears: sort the trades by price, aggregate volume at each level, then walk the cumulative sum until you cross the halfway point. The wrinkle is that multiple trades at the same price must be grouped before you compute cumulative volumes. This is the kind of utility function that appears in real trading systems and must handle edge cases cleanly.
- Aggregating trades by price level
- Cumulative sum logic and boundary detection
- Rounding and numeric precision
- Why median is more robust than mean for skewed volume distributions