backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Error of plot_heatmaps()

Open vladiscripts opened this issue 2 years ago • 0 comments

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

vladiscripts avatar Feb 06 '23 07:02 vladiscripts