I want to short an index stock whenever I buy another common stock. For instance, if I buy $10,000 worth of IBM, I want to short $10,000 worth of IWM (or another index) at the same time and then close both positions at the same time. How do I write the code to backtest this?
