diff --git a/backtesting/_stats.py b/backtesting/_stats.py index 2d8de0ca..b22dfa2f 100644 --- a/backtesting/_stats.py +++ b/backtesting/_stats.py @@ -64,13 +64,15 @@ def compute_stats( 'ExitBar': [t.exit_bar for t in trades], 'EntryPrice': [t.entry_price for t in trades], 'ExitPrice': [t.exit_price for t in trades], + 'SL': [t.sl for t in trades], + 'TP': [t.tp for t in trades], 'PnL': [t.pl for t in trades], 'ReturnPct': [t.pl_pct for t in trades], 'EntryTime': [t.entry_time for t in trades], 'ExitTime': [t.exit_time for t in trades], - 'Tag': [t.tag for t in trades], }) trades_df['Duration'] = trades_df['ExitTime'] - trades_df['EntryTime'] + trades_df['Tag'] = [t.tag for t in trades] commissions = sum(t._commissions for t in trades) del trades diff --git a/backtesting/test/_test.py b/backtesting/test/_test.py index 5d7aa20d..d5373f1a 100644 --- a/backtesting/test/_test.py +++ b/backtesting/test/_test.py @@ -335,7 +335,7 @@ def almost_equal(a, b): self.assertSequenceEqual( sorted(stats['_trades'].columns), - sorted(['Size', 'EntryBar', 'ExitBar', 'EntryPrice', 'ExitPrice', + sorted(['Size', 'EntryBar', 'ExitBar', 'EntryPrice', 'ExitPrice', 'SL', 'TP', 'PnL', 'ReturnPct', 'EntryTime', 'ExitTime', 'Duration', 'Tag'])) def test_compute_stats_bordercase(self):