| 604 | bt.plot(filename=f, open_browser=False) |
| 605 | |
| 606 | def test_method_sambo(self): |
| 607 | bt = Backtest(GOOG.iloc[:100], SmaCross, finalize_trades=True) |
| 608 | res, heatmap, sambo_results = bt.optimize( |
| 609 | fast=range(2, 20), slow=np.arange(2, 20, dtype=object), |
| 610 | constraint=lambda p: p.fast < p.slow, |
| 611 | max_tries=30, |
| 612 | method='sambo', |
| 613 | return_optimization=True, |
| 614 | return_heatmap=True, |
| 615 | random_state=2) |
| 616 | self.assertIsInstance(res, pd.Series) |
| 617 | self.assertIsInstance(heatmap, pd.Series) |
| 618 | self.assertGreater(heatmap.max(), 1.1) |
| 619 | self.assertGreater(heatmap.min(), -2) |
| 620 | self.assertEqual(-sambo_results.fun, heatmap.max()) |
| 621 | self.assertEqual(heatmap.index.tolist(), heatmap.dropna().index.unique().tolist()) |
| 622 | |
| 623 | def test_max_tries(self): |
| 624 | bt = Backtest(GOOG.iloc[:100], SmaCross) |