Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How does the multiprocessing work in windows? #441

Unanswered
ahfattahi asked this question in Q&A
Discussion options

``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())
You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

If parallel computing is not available for Windows yet, do you have a suggestion for using other parallel computing libraries?

You must be logged in to vote
4 replies
Comment options

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.

Comment options

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?

Comment options

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?

Comment options

@ahfattahi @stnatter Long time. Did you guys find any solutions for that? How can we run distex for backtesting.py?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /