mirror of
https://github.com/KhizarImran/backtestingfx.git
synced 2026-11-02 03:26:11 +00:00
Adds two Broker methods for path-dependent strategies: - close_partial(id, lot_size) scales out of a position and leaves the remainder open under the same id, so it can keep being managed. - update_sl(id, stop_loss) moves the stop in place. A trailing stop no longer has to close and reopen, which paid spread and commission on every step. Both are reachable from Python as Strategy.close_partial and Strategy.update_sl. Closing a position, part of one, or the whole book previously repeated the same PnL and commission arithmetic in four places. That is now one settle() helper taking the number of lots to close, so a partial close is the same code with a smaller number and the feature made broker.rs shorter rather than longer. Commission splits across the legs: the entry was charged on the full size when the position opened, so settle only takes the exit leg for the lots being closed. Two 0.5 closes land on the same cash as one 1.0 close, which is what closing_partially_twice_matches_closing_once pins. update_sl deliberately does not check which way the stop moves, since widening a stop is a legitimate thing for a strategy to do.