kernc/backtesting.py

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

Aperta

#1335 aperta il 8 dic 2025

 (0 commenti) (0 reazioni) (0 assegnatari)Python (863 fork)batch import
bughelp wanted

Metriche repository

Star
 (4387 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Enhancement description

Hi,

Full spread is currently applied to buy price on trade open and open+close commission only on trade close. This doesn't reflect real life and affects backtesting stop loss/trailing stop loss trigger level. Also,, I'm using trade.pl_pct for trailing stop loss calculation and I have to subtract commission manually. It also leads to bad optimization.

The situation should be :

  • trade open: apply half-spread on buy price and also apply commission
  • trade close: apply half-spread on sell price and also apply commission

Thanks a lot!

Code sample

Additional info, images

No response

Guida contributor