|
1 | 1 | import inspect |
2 | 2 | import os |
3 | 3 | import sys |
4 | | -import time |
| 4 | +from timeit import default_timer |
5 | 5 | import unittest |
6 | 6 | import warnings |
7 | 7 | from concurrent.futures.process import ProcessPoolExecutor |
8 | 8 | from contextlib import contextmanager |
9 | 9 | from glob import glob |
10 | 10 | from runpy import run_path |
11 | 11 | from tempfile import NamedTemporaryFile, gettempdir |
| 12 | +from time import time |
12 | 13 | from unittest import TestCase |
13 | 14 | from unittest.mock import patch |
14 | 15 |
|
@@ -578,6 +579,25 @@ def test_method_openbox(self): |
578 | 579 | random_state=2) |
579 | 580 | self.assertIsInstance(res, pd.Series) |
580 | 581 |
|
| 582 | + def test_timing(self): |
| 583 | + bt = Backtest(GOOG.iloc[:100], SmaCross) |
| 584 | + |
| 585 | + for method in ["sklearn", "openbox"]: |
| 586 | + start = default_timer() |
| 587 | + res = bt.optimize( |
| 588 | + fast=range(2, 20), slow=np.arange(2, 20, dtype=object), |
| 589 | + constraint=lambda p: p.fast < p.slow, |
| 590 | + max_tries=30, |
| 591 | + method='openbox', |
| 592 | + return_optimization=False, |
| 593 | + return_heatmap=False, |
| 594 | + n_initial_points=0, |
| 595 | + init_strategy='latin_hypercube', |
| 596 | + random_state=2) |
| 597 | + end = default_timer() |
| 598 | + print(f"Method {method} took {end-start} seconds") |
| 599 | + self.assertIsInstance(res, pd.Series) |
| 600 | + |
581 | 601 | def test_max_tries(self): |
582 | 602 | bt = Backtest(GOOG.iloc[:100], SmaCross) |
583 | 603 | OPT_PARAMS = {'fast': range(2, 10, 2), 'slow': [2, 5, 7, 9]} |
|
0 commit comments