Let's say I have a strategy with multiple rules that generates multiple orders on the same symbol at the same timestamp. For example, on 2012-05-23 one rule might buy 10 shares of IBM while another rule sells 5 shares of IBM. In production, a reasonable system would use netting and execute one order to buy 5 shares, rather than one order to buy 10 shares and another order to sell 5 shares.
Is there a way to get this behaviour in quantstrat
? From my experiments, quantstrat
does not do netting, and for example will add transaction fees for both opposing orders as if two separate orders were executed.
If quantstrat
cannot net orders then it should still be possible to obtain the desired PnL in backtesting by using a custom TxnFees
function. If this is the correct way to go, how would one go about defining a custom function to net the transaction fees?