Skip to content

BRK: Apply spread at trade entry and exit#1375

Open
nyxst4ck wants to merge 2 commits into
kernc:masterfrom
nyxst4ck:agent/half-spread-round-trip-costs
Open

BRK: Apply spread at trade entry and exit#1375
nyxst4ck wants to merge 2 commits into
kernc:masterfrom
nyxst4ck:agent/half-spread-round-trip-costs

Conversation

@nyxst4ck

@nyxst4ck nyxst4ck commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Closes #1335.

Summary

  • apply the configured bid-ask spread adversely at both trade entry and trade exit
  • retain the existing commission model, including recalculation for each transaction
  • document the two-sided spread behavior
  • cover long/short round trips, reversals, stop-loss fills, and updated equity expectations

This revision follows the maintainer feedback: the spread is no longer split in half, and the commission accounting changes from the earlier draft have been removed.

Validation

  • python -m backtesting.test — 81 passed, 1 skipped
  • git diff --check

Co-Authored-By: claude-flow <ruv@ruv.net>
@kernc

kernc commented Jul 21, 2026

Copy link
Copy Markdown
Owner

@nyxst4ck Thanks for picking this up!

  1. split the configured bid-ask spread equally between trade entry and exit

Modelling spread as a share of price is somewhat eccentric and variable already. But then "you need to further compute halves" will be a documentation nightmare, leaving the logic all but simple. Spread is property of the instrument and it affects us, in whole, when entering the trade.

Then it affects us again when we try to sell the gold! Thus, to be precise, I'm thinking spread should also be accounted for twice. 🤔😳

But this shall break a lot of existing expected values.

But breaking spread in half is a decisive no-go. 👎

  1. preserve the commission actually charged at entry instead of recomputing it at close

This is also not how exchanges do. The commission, for what I see, is computed again based on the order value at the time of the transaction.

  1. allocate entry commission proportionally when a trade is partially closed

Fixing 3. proper makes this a no-op.

@nyxst4ck nyxst4ck changed the title BUG: Split spread across entry and exit BUG: Apply spread at trade entry and exit Jul 21, 2026
@nyxst4ck
nyxst4ck marked this pull request as ready for review July 21, 2026 22:24
@kernc kernc changed the title BUG: Apply spread at trade entry and exit BRK: Apply spread at trade entry and exit Jul 22, 2026
Rework the proposed behavior to charge the configured spread at trade entry and exit while retaining per-transaction commission calculation.
@nyxst4ck
nyxst4ck force-pushed the agent/half-spread-round-trip-costs branch from fc94f71 to 4670a84 Compare July 25, 2026 03:06
@nyxst4ck

Copy link
Copy Markdown
Contributor Author

Makes sense, thanks for the detailed explanation. Reworked: spread is now applied in full at both entry and exit (_adjusted_price no longer halves it), and the proportional entry-commission allocation on partial closes is gone — commission is simply recomputed per transaction, same as before. python -m backtesting.test: 81 passed, 1 skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply half-spread and commission on both open/close trade

2 participants