-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
``Hi,
I am running the backtest.optimizer() on a small dataset, but only one core of CPU is being used. There is a TODO written in the library description that implies 'spawn' method is not yet implemented in the code. Does it mean windows users cannot utilize multiprocessing? if not, how can I force the optimizer to use more CPU cores?
Here is my example code:
from multiprocessing import set_start_method
from backtesting import Strategy, Backtest
from backtesting.lib import resample_apply
import talib as ta
class TestStra(Strategy):
RSI_level = 30
SO_level = 30
# MACD mode: macd=0, macdSignal=1, macdHist=2
MACD_mode=2
# SO mode: k=0, d=1
SO_mode = 1
set_start_method = 'spawn'
def init(self):
# Call Indicators
self.MACD = self.I(ta.MACD, self.data.Close)
self.MACD = self.MACD[self.MACD_mode]
self.SO = self.I(ta.STOCH,self.data.High,self.data.Low,self.data.Close)
self.SO = self.SO[self.SO_mode]
def next(self):
if (self.position.is_long and
self.MACD[-1] > 0 and
self.MACD[-2] > self.MACD[-1]):
self.position.close()
elif (self.position.is_short and
self.MACD[-1] < 0 and
self.MACD[-2] < self.MACD[-1]):
self.position.close()
elif self.SO[-1] < self.SO_level :
self.buy()
elif self.SO[-1] > (100-self.SO_level):
self.sell()
from backtesting.test import EURUSD
backtest = Backtest(EURUSD, TestStra, cash= 1000, margin=0.03)
stats, heatmap = backtest.optimize(
RSI_level=range(10, 50, 5),
SO_level=range(10, 50, 5),
maximize='Equity Final [$]',
max_tries=200,
random_state=0,
return_heatmap=True)
print(backtest.run())
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 4 replies
-
If parallel computing is not available for Windows yet, do you have a suggestion for using other parallel computing libraries?
Beta Was this translation helpful? Give feedback.
All reactions
-
I like this: https://github.com/erdewit/distex
It is a super sleek package I have been using in my own system without any problems.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks. I don't know how to define parameter ranges ( as it is defined in backtest.optimize() ).
Would you please provide an example where you use this package with backtesting.py and define parameters ranges?
Beta Was this translation helpful? Give feedback.
All reactions
-
I like this: https://github.com/erdewit/distex It is a super sleek package I have been using in my own system without any problems.
Thanks. I don't know how to define parameter ranges ( as it is defined in backtest.optimize() ).
Would you please provide an example where you use this package with backtesting.py and define parameters ranges?
Beta Was this translation helpful? Give feedback.
All reactions
-
@ahfattahi @stnatter Long time. Did you guys find any solutions for that? How can we run distex for backtesting.py?
Beta Was this translation helpful? Give feedback.