@@ -218,7 +218,7 @@ def next(self, _FEW_DAYS=pd.Timedelta('3 days')): # noqa: N803
218218 bt = Backtest (GOOG , Assertive )
219219 with self .assertWarns (UserWarning ):
220220 stats = bt .run ()
221- self .assertEqual (stats ['# Trades' ], 145 )
221+ self .assertEqual (stats ['# Trades' ], 144 )
222222
223223 def test_broker_params (self ):
224224 bt = Backtest (GOOG .iloc [:100 ], SmaCross ,
@@ -282,7 +282,7 @@ def test_compute_drawdown(self):
282282 np .testing .assert_array_equal (peaks , pd .Series ([7 , 4 ], index = [3 , 5 ]).reindex (dd .index ))
283283
284284 def test_compute_stats (self ):
285- stats = Backtest (GOOG , SmaCross ).run ()
285+ stats = Backtest (GOOG , SmaCross , finalize_trades = True ).run ()
286286 expected = pd .Series ({
287287 # NOTE: These values are also used on the website!
288288 '# Trades' : 66 ,
@@ -438,7 +438,8 @@ def next(self):
438438 elif len (self .data ) == len (SHORT_DATA ):
439439 self .position .close ()
440440
441- self .assertFalse (Backtest (SHORT_DATA , S ).run ()._trades .empty )
441+ self .assertTrue (Backtest (SHORT_DATA , S , finalize_trades = False ).run ()._trades .empty )
442+ self .assertFalse (Backtest (SHORT_DATA , S , finalize_trades = True ).run ()._trades .empty )
442443
443444 def test_check_adjusted_price_when_placing_order (self ):
444445 class S (Strategy ):
@@ -540,7 +541,7 @@ def test_autoclose_trades_on_finish(self):
540541 def coroutine (self ):
541542 yield self .buy ()
542543
543- stats = self ._Backtest (coroutine ).run ()
544+ stats = self ._Backtest (coroutine , finalize_trades = True ).run ()
544545 self .assertEqual (len (stats ._trades ), 1 )
545546
546547 def test_order_tag (self ):
@@ -587,7 +588,7 @@ def test_optimize(self):
587588 bt .plot (filename = f , open_browser = False )
588589
589590 def test_method_sambo (self ):
590- bt = Backtest (GOOG .iloc [:100 ], SmaCross )
591+ bt = Backtest (GOOG .iloc [:100 ], SmaCross , finalize_trades = True )
591592 res , heatmap , sambo_results = bt .optimize (
592593 fast = range (2 , 20 ), slow = np .arange (2 , 20 , dtype = object ),
593594 constraint = lambda p : p .fast < p .slow ,
@@ -925,7 +926,7 @@ def init(self):
925926 self .data .Close < sma )
926927
927928 stats = Backtest (GOOG , S ).run ()
928- self .assertIn (stats ['# Trades' ], (1181 , 1182 )) # varies on different archs?
929+ self .assertIn (stats ['# Trades' ], (1179 , 1180 )) # varies on different archs?
929930
930931 def test_TrailingStrategy (self ):
931932 class S (TrailingStrategy ):
@@ -941,7 +942,7 @@ def next(self):
941942 self .buy ()
942943
943944 stats = Backtest (GOOG , S ).run ()
944- self .assertEqual (stats ['# Trades' ], 57 )
945+ self .assertEqual (stats ['# Trades' ], 56 )
945946
946947
947948class TestUtil (TestCase ):
0 commit comments