Commit Graph
6 Commits
Author SHA1 Message Date
KhizarImran 7627094c63 feat: partial close and in-place stop loss updates
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.
2026-08-30 11:16:37 +01:00
KhizarImran 4b4d53dd26 new: optimise.rs which handles optimisation. also linked into the python 2026-08-02 22:25:03 +01:00
Khizar c31e0088db feat: add standalone HTML reports 2026-07-17 14:54:59 +00:00
KhizarImranandClaude Sonnet 4.6 e88dc28b2f docs: add PyPI badge to README
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 19:00:52 +01:00
KhizarImran 2252b4cd8c publised to pypi 2026-06-21 18:14:03 +01:00
Khizar Imran e5c82056bc new: README file 2026-06-04 00:33:30 +01:00