position -= NUM_SHARES_PER_TRADE # reduce position by the size of this trade
sell_sum_qty += NUM_SHARES_PER_TRADE
so the remaining position : abs(position)
Line 106 : open_pnl += abs(position) (close_price - buy_sum_price_qty / buy_sum_qty)
and the author line 111 : open_pnl += abs(buy_sum_qty - position) (sell_sum_price_qty/sell_sum_qty - close_price)
also need to be corrected:
Line 111 : open_pnl += abs(buy_sum_qty - position) * (sell_sum_price_qty/sell_sum_qty - close_price)
mark the remaining position to market i.e. pnl would be what it would be if we closed at current price
author line 106 : open_pnl += abs(sell_sum_qty - position) * (close_price - buy_sum_price_qty / buy_sum_qty)
should be corrected since:
position -= NUM_SHARES_PER_TRADE # reduce position by the size of this trade sell_sum_qty += NUM_SHARES_PER_TRADE so the remaining position : abs(position) Line 106 : open_pnl += abs(position) (close_price - buy_sum_price_qty / buy_sum_qty) and the author line 111 : open_pnl += abs(buy_sum_qty - position) (sell_sum_price_qty/sell_sum_qty - close_price) also need to be corrected: Line 111 : open_pnl += abs(buy_sum_qty - position) * (sell_sum_price_qty/sell_sum_qty - close_price)
Note: abs(position) = abs(buy_sum_qty-sell_sum_qty)