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

Error of plot_heatmaps() #901

Open
vladiscripts opened this issue Feb 6, 2023 · 0 comments · May be fixed by #1037
Open

Error of plot_heatmaps() #901

vladiscripts opened this issue Feb 6, 2023 · 0 comments · May be fixed by #1037
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@vladiscripts
Copy link

Expected Behavior

Fix the mistake or make it a normal explanation.

Actual Behavior

Traceback (most recent call last):
  File "... .py", line 298, in optimize
    plot_heatmaps(heatmap, agg='mean')
  File "... /backtesting/lib.py", line 141, in plot_heatmaps
    return _plot_heatmaps(heatmap, agg, ncols, filename, plot_width, open_browser)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "... /backtesting/_plotting.py", line 685, in plot_heatmaps
    low=min(df.min().min() for df in dfs),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: min() arg is an empty sequence

There dfs specified in the error is an empty [].

Steps to Reproduce

from backtesting.lib import plot_heatmaps

...
stats, heatmap = bt.optimize(a_test_param=range(5), maximize='Equity Final [$]', return_heatmap=True)

plot_heatmaps(heatmap, agg='mean')

The error is raised when plot_heatmaps() run.
I think, the reason is that for a graph with two axes (X, Y) need at least 2 optimized variables. Therefore, this method does not accept the heatmap that is derived from bt.optimize() that was run with only one parameter to be optimized.

Additional info

  • Backtesting version: 0.3.3
@kernc kernc added bug Something isn't working good first issue Good for newcomers labels Feb 6, 2023
siufai6 added a commit to siufai6/backtesting.py that referenced this issue Aug 3, 2023
Heatmap plots requires at least two parameters (variables) in the heatmap Series.  Add an assert before calling _plot_heatmap to guard against the case of having only 1 variable.
siufai6 added a commit to siufai6/backtesting.py that referenced this issue Aug 4, 2023
@kernc kernc linked a pull request Aug 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants