Execution Simulator
Hard ● Live C++ Rust Java PythonThe Problem
Implement TWAP (Time-Weighted Average Price) and VWAP (Volume-Weighted Average Price) execution algorithms. Given a parent order of N shares and 1 million OHLCV bars, optimally split execution to minimize implementation shortfall.
Compute metrics: execution prices, shortfall, total costs, bars executed. Test interview skills for quant trading and HFT roles.
Evaluation Criteria
Correctness (70%)
Both strategies must execute correct total quantity. Shortfall and prices accurate to 6 decimal places.
Performance (30%)
Wall-clock time on 1M bars with 100K share parent order.
Input Format
- First line
SIDE PARENT_QTY NUM_BARSwhere SIDE is BUY or SELL, PARENT_QTY is the total quantity to execute, NUM_BARS is the number of OHLCV bars that follow.- Each bar
timestamp,open,high,low,close,volume(comma-separated).- Two algorithms to run
- TWAP (equal time slices across all bars) and VWAP (weighted by each bar's volume share).
Output Format & Sample
Sample input (first 8 lines, full file linked below):
BUY 100000 30 1700000000,99.99,100.07,99.90,99.95,13339 1700000001,99.93,100.68,99.19,100.52,12521 1700000002,100.50,100.56,100.44,100.47,15032 1700000003,100.53,100.59,100.48,100.55,15269 1700000004,100.57,101.23,99.92,100.98,12038 1700000005,101.03,101.76,100.31,100.80,12932 1700000006,100.89,101.01,100.77,100.79,12580 ... (more)
Expected output for that sample (first 8 lines):
99.990000 100.728576 100.728433 0.007386 0.007385 10072857.580000 10072843.317500 30 ... (more)
↓ download full sample input | ↓ download expected output
Test your solution locally:
./your_solution < input.txt | diff - output.txt
Common Pitfalls
- Execute per-bar at the bar's VWAP-ish midpoint. The reference uses
(high + low) / 2as the fill price for the slice; using close-only will diverge from the expected output. - TWAP integer slicing: qty per bar = floor(PARENT_QTY / NUM_BARS), with the remainder added to the last bar so totals match.
- VWAP slicing: qty_per_bar[i] = round(PARENT_QTY * volume[i] / sum(volume)). Sum of slices must equal PARENT_QTY exactly; adjust the last slice for rounding error.
- Implementation shortfall = (avg_exec_price - arrival_price) * sign(side) * PARENT_QTY. Arrival price = open[0].
- Output is 9 metrics in the order: arrival_price, twap_avg_price, vwap_avg_price, twap_shortfall, vwap_shortfall, twap_total_cost, vwap_total_cost, twap_slices, vwap_slices.
Performance Tier Thresholds (applied by the grader)
| Language | Gold | Silver | Bronze | Tier 4 |
|---|---|---|---|---|
| C++ | <500ms | <2000ms | <10000ms | else PASS |
| Rust | <500ms | <2000ms | <10000ms | else PASS |
| Java | <1000ms | <4000ms | <15000ms | else PASS |
| Python | <5000ms | <15000ms | <60000ms | else PASS |
Submission Rules
- Single-file solutions only. All code must be in one file.
- Your program must read from stdin and write to stdout.
- Java class must be named Solution.
- No network access, no filesystem access beyond stdin/stdout.
- Time limit: 120 seconds. Memory limit: 2 GB.