Build an audit module for a high-frequency trading platform that processes an asynchronous, out-of-order data stream containing trade execution logs from multiple exchanges. The task is to reconstruct the chronological execution timeline for a specified exchange (target_venue), and find the maximum number of consecutive trade logs in a contiguous execution window that satisfies specific operational risk limits.
You are given an array of log objects logs, a target exchange identifier target_venue, a maximum allowed price deviation V, and a maximum cumulative slippage budget S. Process and solve it according to the following steps:
- Filter: select the log records whose
venueequalstarget_venue. - Reconstruct: sort the filtered records by
timestampin ascending order. - Calculate Metric: for each log, compute its slippage cost:
slippage_cost = abs(fill_price - benchmark_price) * volume. - Evaluate Window: in the sorted logs, find the length of the longest contiguous sub-sequence that satisfies both of the following conditions at the same time:
- The difference between the max price and the min price in the window is no greater than V:
max(fill_price) - min(fill_price) <= V - The sum of the slippage costs of all logs in the window is no greater than S:
sum(slippage_cost) <= S
- The difference between the max price and the min price in the window is no greater than V:
- Return: return the length of the longest window that satisfies the conditions above (i.e., the number of logs). If no valid window exists, or no logs match after filtering, return 0.
Discussion
Loading comments…