-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Backtest.plot() fails with resampling #987
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
Comments
Hi there @bellerofonte , However this seems to be related to your pandas version as in https://pandas.pydata.org/docs/reference/api/pandas.Index.get_loc.html I used pandas However after upgrading to 2.0.1 the error still did not appear. Would need your data and code on how you created your dataframe to dive deeper. You can try to downgrade pandas to Here is my code and data for reference. CODE
OUPUT
Candles have been successfully resampled to 2H ![]() ![]() ![]() I used 5min data. |
I'm getting the same error. Of note, if I reset the index in the dataframe from a datetime index to a regular integer index then the plot works. My pandas was also v 2.0.1 I just needed something quick so I haven't had a chance to deal with it and doubt I will. I just thought I would share here in case it helps you all to diagnose it. |
Not sure if this would work, but it seems like they cover this issue here. I will volunteer to do pr if it is as simple as changing the line in _plotting.py cc @kernc |
@eervin123 Thank you for sharing. Additionally could you send your code and data you used. |
Okay @DominikBerger01 I'll try to get to that tonight. PST |
fyi, I was able to get it to work with bt.plot(resample=False) |
@DominikBerger01 here you go. the Happy hunting 😊 |
@eervin123 Many thanks, will start exploring tomorrow morning. ;) |
I was able to reproduce the bug. After trying to solve it I have found that it already was solved and pushed to main back in Dezember 2022. This was the PR: dfba461 Also looks to me like the correct implementation as all tests passed: OLD (causing error and tests to fail) So I guess we'll have to wait for the next release. Which in my opinion should happen sooner than later as most of the people getting the current version will be bugged by this. :) |
@DominikBerger01 @eervin123 thank you for your effort spent on finding the problem! Is it a good idea to add |
@bellerofonte You also would need to change it from I haven't tried this yet but it is pretty simple to make the change and then try it out. If it doesn't work you can undo the change and all will be as before. Thank you to you @DominikBerger01 for investigating. Open source FTW! |
You could change the source code. However I wouldn't recommend it. A more common approach would be to pip install the latest changes directly from Github. Here is how: Step 1 Step 2 This should install the latest changes from Step 3 The hash you see at the end btw refers to the hash of the latest commit: (0ce24d8) Now you have the latest version with unreleased changes which should fix your bug. |
@DominikBerger01 I can confirm your method solves the issue. Thanks a lot! |
Just wanted to help out, Source: https://pandas.pydata.org/pandas-docs/version/1.5/reference/api/pandas.Index.get_loc.html |
I just got this error, and the steps quoted above from a prior post fixed my issue. Thanks! I'm looking forward to the next release so this issue is fixed without the work around. |
|
Expected Behavior
charts plotted
Actual Behavior
following exception:
Steps to Reproduce
Additional info
however, if I change
next
method to following:chart would be plotted successfully without equity curve
the dataset contains 800k+ of 1M candles
The text was updated successfully, but these errors were encountered: