Thanks for posting this problem, I am having a similar issue when comparing backtesting.py with TV , commission fees differ significantly. After considerable digging I have a theory that backtesting.py is not computing fees on the Exit Price (at least the math points in that direction). This may be my settings or something deeper. Hopefully @kernc will comment...
I have attached two screen shots one of trade results for TV and the other stats _trades. backtesting.py & TV are using coinbases' stupid high fee of .004% no slippage and the data uploaded in backtesting.py is the same data downloaded from TV chart using 1m time frame.
My observations:
TV Entry Price is the same as close and reflects no fee. .2166
BT.py Entry Price shows the purchase with fee applied .2166* 1.004 = .217466 which is correct.
TV Exit Price shows .2183
BT.py Exit Price is also .2183
TV shows a profit on this trade of -.06 while BT.py shows a profit of 1.2504
profit proceeds-costs or 327.45 - 326.199 = 1.25 - math checks out -
In a nutshell TV is computing fees (entry price size) 1.004 where as backtesting.py appears to be computing commision by (Entry price 1.004) size. I think both methods are correct, the results are the same. However, TV computes both purchase and sale, BT appears to compute on the purchase only.
Thanks for posting this problem, I am having a similar issue when comparing backtesting.py with TV , commission fees differ significantly. After considerable digging I have a theory that backtesting.py is not computing fees on the Exit Price (at least the math points in that direction). This may be my settings or something deeper. Hopefully @kernc will comment...
I have attached two screen shots one of trade results for TV and the other stats _trades. backtesting.py & TV are using coinbases' stupid high fee of .004% no slippage and the data uploaded in backtesting.py is the same data downloaded from TV chart using 1m time frame.
self.buy(size=1500, sl=(1 - self.stoploss) * self.data.Close, tp=(1+self.takeprofit)*self.data.Close)
bt = Backtest(data, scalp, cash=500, commission=.004,trade_on_close=True, exclusive_orders=True)
My observations: TV Entry Price is the same as close and reflects no fee. .2166 BT.py Entry Price shows the purchase with fee applied .2166* 1.004 = .217466 which is correct. TV Exit Price shows .2183 BT.py Exit Price is also .2183 TV shows a profit on this trade of -.06 while BT.py shows a profit of 1.2504
TV math:
BT.py math:
In a nutshell TV is computing fees (entry price size) 1.004 where as backtesting.py appears to be computing commision by (Entry price 1.004) size. I think both methods are correct, the results are the same. However, TV computes both purchase and sale, BT appears to compute on the purchase only.
Originally posted by @MrDenfish in https://github.com/kernc/backtesting.py/discussions/734#discussioncomment-6200892