Replies: 1 comment
-
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 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. |
Beta Was this translation helpful? Give feedback.
-
Hey!
So i am backtesting a strategy i found in TradingView and as a selfcheck, i try to match results with those of TradingView.
When i exclude commissions from the backtest, results do match nicely (i actually exported chart data from TradingView so that i can be sure i am working with the same data).
But when i add commissions to the picture, it takes double of those fees in TradingView to match the results in backtesting.
`def MOM(values, n):
return talib.MOM(pd.Series(values), timeperiod = n)
class MomTrade(Strategy):
# Define timeperiod for momentum
n = 2
bt = Backtest(df, MomTrade, cash=100000, commission=0.0004)
stats = bt.run(n=10)
stats`
Nothing fancy in terms of code, as you can see.
In TV, i have to put 0.02 (half of what is used in the above example) to match the results in terms of trades, return, etc.
Beta Was this translation helpful? Give feedback.
All reactions