11import inspect
2+ import multiprocessing as mp
23import os
34import sys
45import 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