Description
Expected behavior
It appears the commission is being added directly to the per-unit adjusted price in:
backtesting.py/backtesting/backtesting.py
Line 944 in d271812
Python
adjusted_price_plus_commission = adjusted_price + self._commission(order.size, price)
If self._commission returns a total commission for the entire order (not per unit), this addition is not correct, since it adds the entire commission fee to each unit price. The commission should either be distributed per unit before adding, or added as a lump sum after computing the total order cost.
Expected behavior: Commission should be correctly applied to the order total, not to each unit, unless self._commission returns a per-unit commission.
Suggested fix: Change the calculation so that the commission is only added once per order, or ensure that self._commission returns a per-unit fee if this logic is intended.
Code sample
bt = Backtest(
data,
DCAStrategy,
cash=1000,
commission=0.0005,
trade_on_close=True,
finalize_trades=True,
margin=1/1,
)
Actual behavior
Additional info, steps to reproduce, full crash traceback, screenshots
No response
Software versions
backtesting.__version__
: 0.6.4pandas.__version__
: 2.2.3numpy.__version__
: 2.1.3bokeh.__version__
: 3.7.0- OS: Win 10