Skip to content

Commit 8b83b35

Browse files
committed
BUG: Fix numpy.random generation in Backtest.optimize
Fixes #500
1 parent 7671f04 commit 8b83b35

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: backtesting/backtesting.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import numpy as np
2222
import pandas as pd
23+
from numpy.random import default_rng
2324

2425
try:
2526
from tqdm.auto import tqdm as _tqdm
@@ -1254,7 +1255,7 @@ def optimize(self, *,
12541255
[plotting tools]: https://scikit-optimize.github.io/stable/modules/plots.html
12551256
12561257
If you want reproducible optimization results, set `random_state`
1257-
to a fixed integer or a `numpy.random.RandomState` object.
1258+
to a fixed integer random seed.
12581259
12591260
Additional keyword arguments represent strategy arguments with
12601261
list-like collections of possible values. For example, the following
@@ -1321,7 +1322,7 @@ def _grid_size():
13211322
return size
13221323

13231324
def _optimize_grid() -> Union[pd.Series, Tuple[pd.Series, pd.Series]]:
1324-
rand = np.random.RandomState(random_state).random
1325+
rand = default_rng(random_state).random
13251326
grid_frac = (1 if max_tries is None else
13261327
max_tries if 0 < max_tries <= 1 else
13271328
max_tries / _grid_size())

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'write_to': os.path.join('backtesting', '_version.py'),
3232
},
3333
install_requires=[
34-
'numpy',
34+
'numpy >= 1.17.0',
3535
'pandas >= 0.25.0, != 0.25.0',
3636
'bokeh >= 1.4.0',
3737
],

0 commit comments

Comments
 (0)