@@ -218,7 +218,7 @@ def next(self, _FEW_DAYS=pd.Timedelta('3 days')): # noqa: N803
218
218
bt = Backtest (GOOG , Assertive )
219
219
with self .assertWarns (UserWarning ):
220
220
stats = bt .run ()
221
- self .assertEqual (stats ['# Trades' ], 145 )
221
+ self .assertEqual (stats ['# Trades' ], 144 )
222
222
223
223
def test_broker_params (self ):
224
224
bt = Backtest (GOOG .iloc [:100 ], SmaCross ,
@@ -282,7 +282,7 @@ def test_compute_drawdown(self):
282
282
np .testing .assert_array_equal (peaks , pd .Series ([7 , 4 ], index = [3 , 5 ]).reindex (dd .index ))
283
283
284
284
def test_compute_stats (self ):
285
- stats = Backtest (GOOG , SmaCross ).run ()
285
+ stats = Backtest (GOOG , SmaCross , finalize_trades = True ).run ()
286
286
expected = pd .Series ({
287
287
# NOTE: These values are also used on the website!
288
288
'# Trades' : 66 ,
@@ -438,7 +438,8 @@ def next(self):
438
438
elif len (self .data ) == len (SHORT_DATA ):
439
439
self .position .close ()
440
440
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 )
442
443
443
444
def test_check_adjusted_price_when_placing_order (self ):
444
445
class S (Strategy ):
@@ -540,7 +541,7 @@ def test_autoclose_trades_on_finish(self):
540
541
def coroutine (self ):
541
542
yield self .buy ()
542
543
543
- stats = self ._Backtest (coroutine ).run ()
544
+ stats = self ._Backtest (coroutine , finalize_trades = True ).run ()
544
545
self .assertEqual (len (stats ._trades ), 1 )
545
546
546
547
def test_order_tag (self ):
@@ -587,7 +588,7 @@ def test_optimize(self):
587
588
bt .plot (filename = f , open_browser = False )
588
589
589
590
def test_method_sambo (self ):
590
- bt = Backtest (GOOG .iloc [:100 ], SmaCross )
591
+ bt = Backtest (GOOG .iloc [:100 ], SmaCross , finalize_trades = True )
591
592
res , heatmap , sambo_results = bt .optimize (
592
593
fast = range (2 , 20 ), slow = np .arange (2 , 20 , dtype = object ),
593
594
constraint = lambda p : p .fast < p .slow ,
@@ -925,7 +926,7 @@ def init(self):
925
926
self .data .Close < sma )
926
927
927
928
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?
929
930
930
931
def test_TrailingStrategy (self ):
931
932
class S (TrailingStrategy ):
@@ -941,7 +942,7 @@ def next(self):
941
942
self .buy ()
942
943
943
944
stats = Backtest (GOOG , S ).run ()
944
- self .assertEqual (stats ['# Trades' ], 57 )
945
+ self .assertEqual (stats ['# Trades' ], 56 )
945
946
946
947
947
948
class TestUtil (TestCase ):
0 commit comments