Commit Graph
9 Commits
Author SHA1 Message Date
Khizar ImranandGitHub c490f274e6 Document and test stop-first intrabar execution policy (#49) 2026-10-18 15:26:34 +01:00
Khizar Imran 623a0c6976 Reset broker state before independent native engine runs 2026-10-08 20:08:05 +01:00
Khizar Imran 967c358bc0 Fix case-insensitive DataFrame column conversion 2026-10-06 23:07:17 +01:00
Khizar Imran d77ceeeb1a Fix full bid-ask spread semantics and equity marking
Codex 🤖, On behalf of Khizar
2026-10-06 20:56:06 +00:00
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
KhizarImran 4972863b5f perf: replace O(n^2) data slice with a windowed view (~2.6x faster py-next) 2026-07-22 22:37:26 +01:00
Khizar c31e0088db feat: add standalone HTML reports 2026-07-17 14:54:59 +00:00
Khizar 4fcadca02e test: cover Python backtest integration 2026-07-17 14:28:24 +00:00