Skip to content

Commit 45a087c

Browse files
committed
✨: Handle constant params
1 parent fce9f4f commit 45a087c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

backtesting/test/_test.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import inspect
22
import os
33
import sys
4-
import time
4+
from timeit import default_timer
55
import unittest
66
import warnings
77
from concurrent.futures.process import ProcessPoolExecutor
88
from contextlib import contextmanager
99
from glob import glob
1010
from runpy import run_path
1111
from tempfile import NamedTemporaryFile, gettempdir
12+
from time import time
1213
from unittest import TestCase
1314
from unittest.mock import patch
1415

@@ -578,6 +579,25 @@ def test_method_openbox(self):
578579
random_state=2)
579580
self.assertIsInstance(res, pd.Series)
580581

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+
581601
def test_max_tries(self):
582602
bt = Backtest(GOOG.iloc[:100], SmaCross)
583603
OPT_PARAMS = {'fast': range(2, 10, 2), 'slow': [2, 5, 7, 9]}

0 commit comments

Comments
 (0)