MCPcopy Index your code
hub / github.com/kernc/backtesting.py / optimize

Method optimize

backtesting/lib.py:618–635  ·  view source on GitHub ↗

Wraps `backtesting.backtesting.Backtest.optimize`, but returns `pd.DataFrame` with currency indexes in columns. heamap: pd.DataFrame = btm.optimize(...) from backtesting.plot import plot_heatmaps plot_heatmaps(heatmap.mean(axis=1))

(self, **kwargs)

Source from the content-addressed store, hash-verified

616 shmem.close()
617
618 def optimize(self, **kwargs) -> pd.DataFrame:
619 """
620 Wraps `backtesting.backtesting.Backtest.optimize`, but returns `pd.DataFrame` with
621 currency indexes in columns.
622
623 heamap: pd.DataFrame = btm.optimize(...)
624 from backtesting.plot import plot_heatmaps
625 plot_heatmaps(heatmap.mean(axis=1))
626 """
627 heatmaps = []
628 # Simple loop since bt.optimize already does its own multiprocessing
629 for df in _tqdm(self._dfs, desc=self.__class__.__name__, mininterval=2):
630 bt = Backtest(df, self._strategy, **self._bt_kwargs)
631 _best_stats, heatmap = bt.optimize( # type: ignore
632 return_heatmap=True, return_optimization=False, **kwargs)
633 heatmaps.append(heatmap)
634 heatmap = pd.DataFrame(dict(zip(count(), heatmaps)))
635 return heatmap
636
637
638# NOTE: Don't put anything below this __all__ list

Calls 3

optimizeMethod · 0.95
_tqdmFunction · 0.85
BacktestClass · 0.85