Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fees and max_drawdown differ from TradingView #771

Open
tiiiecherle opened this issue Feb 10, 2025 · 2 comments
Open

fees and max_drawdown differ from TradingView #771

tiiiecherle opened this issue Feb 10, 2025 · 2 comments

Comments

@tiiiecherle
Copy link

Hey,

first of all, thanks a lot for this great project.

I managed to build a 1:1 replication of my tradingview strategy and indicators and as of now two things are open that I could not get to work or better to get them in sync between the two systems.

I added Time Conditions for hours, weekdays and a backtesting period and use portfolio_from_signals in vectorbt.

The number of trades, the net profit (when fees are set to 0) and the win rate are an exact match and sync perfectly between the systems.

But I have differences for these two values:

fees
There is a small difference in the fees from tradingview and from vectorbt. But it is not only there in certain conditions, it always there. Could this be due to rounding? If yes, how can I set the number of decimal places to calculate the fees with to get an exact match with tradingview?

max_drawdown
As stated above all trades long and short match exactly and I also debugged the entry and exit prices. Considering max_drawdown the differences are more significant than for fees and differ multiple percents. To rule out open positions I added an exit condition on the last timeframe and checked that all trades are closed at the end of the respective time. I am taking max_drawdown like this:
max_drawdown = portfolio.drawdowns.max_drawdown()

I did everything I could but could not figure out the differences in fees and max_drawdown.

Thanks in advance for looking into it and giving me some hints or advices how to debug this.

Kind regards

@polakowo
Copy link
Owner

VBT is solely based on floating point numbers, thus you cannot set decimal places, neither for fees nor for anything else. There are two solutions: you can calculate fees by yourself, round them, and provide them as fixed_fees (if your order size is known in advance of course), or, you can perform your backtest without fees and then "patch" the order records with the fees with new_pf = pf.replace(order_records=new_order_records).

There shouldn't be no difference between MDD, I'm not aware how it's calculated on TV but in VBT it's based on equity. You can also calculate it from returns with pf.max_drawdown(), which should yield the same number.

@tiiiecherle
Copy link
Author

Thanks for the answers.

fees
As I am pretty new to python I exported portfolio.trades.records_readable to excel and calculated the fees. If I don't round anything it matches your calculation almost exactly. I was not able to replicate the way TV calculates. I tried rounding or cutting the numbers with different decimal places, but none matched the TV result. I will get back to their support and ask how this is calculated before I get back to you to ask how to replicate.

max_drawdown
I found this
https://www.tradingview.com/support/solutions/43000681690-performance-max-drawdown/
how TV calculates its max_drawdown.
I guess vectorBT calculates differently, right?

As I understand correctly on their website exporting portfolio.trades.records_readable is not enough to check as it calculates the drawdown on every low of every bar if I got that right.

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

No branches or pull requests

2 participants