Skip to content

Optimization multithreading broken since 0.6.0 #1220

@timhok

Description

@timhok

Expected behavior

pip install backtesting==0.5.0
time python Squeeze.py
...
real    2m15.172s
user    31m49.496s
sys     0m8.278s

Code sample

from backtesting import Backtest
...
bt = Backtest(data, SqueezeStrategy, cash=10_000, commission=.001, margin=1)

stats = bt.optimize(
		bb_length = range(10, 31, 10),
		bb_std = [1.0, 2.0, 3.0, 4.0],
		kc_length = range(10, 31, 10),
		kc_mult = [1.0, 1.5, 2.0, 2.5],
		rsi_period = range(10, 23, 2),
		maximize='Equity Final [$]')
bt.plot(filename="plot.html")

Actual behavior

pip install backtesting==0.6.0
time python Squeeze.py
...
real    35m53.835s
user    36m41.256s
sys     0m43.006s

Additional info, steps to reproduce, full crash traceback, screenshots

I noticed that when upgrading from version 0.5.0 to 0.6.0 (and 0.6.1) optimization is taking way too long and the cpu usage is very low: running the same exact code on version 0.5.0 takes 2 minutes and uses all 16 cores of my cpu, and on version 0.6.0+ it takes 35 minutes, also "user mode" metric reported by "time" binary is almost the same as "real" which indicates task being run in single thread

Software versions

  • Backtesting version: 0.6.0
  • OS: Ubuntu 22.04.4 LTS
  • Python version: 3.10.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions