File tree Expand file tree Collapse file tree
Open diff view settings
Expand file tree Collapse file tree
Open diff view settings
Original file line number Diff line number Diff line change @@ -1343,6 +1343,11 @@ def run(self, **kwargs) -> pd.Series:
13431343 # strategy iteration. Use the same OHLC values as in the last broker iteration.
13441344 if start < len (self ._data ):
13451345 try_ (broker .next , exception = _OutOfMoneyError )
1346+ elif len (broker .trades ):
1347+ warnings .warn (
1348+ 'Some trades remain open at the end of backtest. Use '
1349+ '`Backtest(..., finalize_trades=True)` to close them and '
1350+ 'include them in stats.' , stacklevel = 2 )
13461351
13471352 # Set data back to full length
13481353 # for future `indicator._opts['data'].index` calls to work
Original file line number Diff line number Diff line change @@ -433,7 +433,8 @@ def next(self):
433433 elif len (self .data ) == len (SHORT_DATA ):
434434 self .position .close ()
435435
436- self .assertTrue (Backtest (SHORT_DATA , S , finalize_trades = False ).run ()._trades .empty )
436+ with self .assertWarnsRegex (UserWarning , 'finalize_trades' ):
437+ self .assertTrue (Backtest (SHORT_DATA , S , finalize_trades = False ).run ()._trades .empty )
437438 self .assertFalse (Backtest (SHORT_DATA , S , finalize_trades = True ).run ()._trades .empty )
438439
439440 def test_check_adjusted_price_when_placing_order (self ):
You can’t perform that action at this time.
0 commit comments