Skip to content

Commit a8d42f0

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

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backtesting/backtesting.py

Lines changed: 3 additions & 2 deletions
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())

0 commit comments

Comments
 (0)