High-frequency algorithmic trading strategies at Citadel and Tower Research continually analyze streaming market quotes across rolling time windows. You are given two equal-length arrays of floating-point numbers, bids and asks, of size , and an integer window size ().
For each sliding window of size ending at index (), the rolling best bid is and the rolling best ask is . The effective spread of the window is defined as:
If , the market is in a crossed or locked condition, presenting an immediate latency arbitrage opportunity.
Your Task
Implement sliding_window_bbo_spread(bids: list[float], asks: list[float], k: int) -> tuple[list[float], list[int]] that returns:
Constraints
Examples
bids = [100.0, 101.5, 102.0, 99.5]
asks = [103.0, 102.5, 101.8, 103.5]
k = 2
# Windows: i=1: min_ask=102.5, max_bid=101.5 -> spread=1.0
# i=2: min_ask=101.8, max_bid=102.0 -> spread=-0.2 (crossed!)
# i=3: min_ask=101.8, max_bid=102.0 -> spread=-0.2 (crossed!)
# Output: ([1.0, -0.2, -0.2], [2, 3])