An algorithmic trade execution router at Jane Street and Citadel must execute a basket of correlated assets ().
Executing asset alters the order book depth and spreads of related assets due to cross-asset market impact. If asset is executed immediately after asset , an empirical cross-impact cost is incurred.
You are provided with an non-negative integer transition impact cost matrix cost_matrix (). You may begin execution with any asset at zero initial transition penalty.
Your Task
Implement min_basket_execution_cost(cost_matrix: list[list[int]]) -> tuple[int, list[int]] that returns:
min_cost: The minimum possible total transition impact cost required to execute all assets.optimal_sequence: The permutation list of asset indices achieving this minimum cost.Constraints
Examples
cost_matrix = [
[0, 10, 15, 20],
[10, 0, 35, 25],
[15, 35, 0, 30],
[20, 25, 30, 0]
]
# Path 1 -> 0 -> 2 -> 3: cost = 10 + 15 + 30 = 55
# Path 2 -> 0 -> 1 -> 3: cost = 15 + 10 + 25 = 50
# Optimal sequence achieves min_cost 50