Skip to content

ENH: Add tqdm to skopt optimization #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 31, 2021
17 changes: 16 additions & 1 deletion backtesting/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ def _tqdm(seq, **_):
}


class SkoptProgressBar:
"""
Progress bar using tqdm for scikit-optimize
Open feature request: https://github.com/scikit-optimize/scikit-optimize/issues/674
"""
def __init__(self, **kwargs):
self._tqdm = _tqdm(**kwargs)

def __call__(self, result):
self._tqdm.update()


class Strategy(metaclass=ABCMeta):
"""
A trading strategy base class. Extend this class and
Expand Down Expand Up @@ -1446,7 +1458,10 @@ def objective_function(**params):
kappa=3,
n_initial_points=min(max_tries, 20 + 3 * len(kwargs)),
initial_point_generator='lhs', # 'sobel' requires n_initial_points ~ 2**N
callback=DeltaXStopper(9e-7),
callback=[
DeltaXStopper(9e-7),
SkoptProgressBar(total=max_tries, desc="Skopt optimizations")
],
random_state=random_state)

stats = self.run(**dict(zip(kwargs.keys(), res.x)))
Expand Down