Describe how to design a backtest system that accounts for latency and transaction costs.
Implement backtest_returns(prices, signals, latency, commission_bps, slippage_bps). prices and signals are arrays of equal length; each signal is a target position of -1, 0, or 1 generated at that index. Execute each signal at index t + latency, ignore orders beyond the array, apply adverse slippage and commission, and return final marked-to-market PnL from an initial flat position.
def backtest_returns(prices, signals, latency, commission_bps, slippage_bps):