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

Appearance settings

Commit 50efc51

Browse filesBrowse files
committed
TST: Expand MultiBacktest parallelism to any mp.context on platform
1 parent 209ce63 commit 50efc51
Copy full SHA for 50efc51

1 file changed

+15-7Lines changed: 15 additions & 7 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎backtesting/test/_test.py‎

Copy file name to clipboardExpand all lines: backtesting/test/_test.py
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import multiprocessing as mp
23
import os
34
import sys
45
import time
@@ -934,13 +935,20 @@ def test_FractionalBacktest(self):
934935
self.assertEqual(stats['# Trades'], 41)
935936

936937
def test_MultiBacktest(self):
937-
btm = MultiBacktest([GOOG, EURUSD, BTCUSD], SmaCross, cash=100_000)
938-
res = btm.run(fast=2)
939-
self.assertIsInstance(res, pd.DataFrame)
940-
self.assertEqual(res.columns.tolist(), [0, 1, 2])
941-
heatmap = btm.optimize(fast=[2, 4], slow=[10, 20])
942-
self.assertIsInstance(heatmap, pd.DataFrame)
943-
self.assertEqual(heatmap.columns.tolist(), [0, 1, 2])
938+
import backtesting
939+
assert callable(getattr(backtesting, 'Pool', None)), backtesting.__dict__
940+
for start_method in mp.get_all_start_methods():
941+
with self.subTest(start_method=start_method), \
942+
patch(backtesting, 'Pool', mp.get_context(start_method).Pool):
943+
start_time = time.monotonic()
944+
btm = MultiBacktest([GOOG, EURUSD, BTCUSD], SmaCross, cash=100_000)
945+
res = btm.run(fast=2)
946+
self.assertIsInstance(res, pd.DataFrame)
947+
self.assertEqual(res.columns.tolist(), [0, 1, 2])
948+
heatmap = btm.optimize(fast=[2, 4], slow=[10, 20])
949+
self.assertIsInstance(heatmap, pd.DataFrame)
950+
self.assertEqual(heatmap.columns.tolist(), [0, 1, 2])
951+
print(start_method, time.monotonic() - start_time)
944952
plot_heatmaps(heatmap.mean(axis=1), open_browser=False)
945953

946954

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.