Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backtesting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def plot(*, results: pd.Series,

df.index.name = None # Provides source name @index
df['datetime'] = df.index # Save original, maybe datetime index
df = df.reset_index(drop=True)
df = df.copy()
df['datetime'] = df.index
equity_data = equity_data.reset_index(drop=True)
index = df.index

Expand Down
10 changes: 10 additions & 0 deletions backtesting/_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def compute_stats(
trades_df['Duration'] = trades_df['ExitTime'] - trades_df['EntryTime']
trades_df['Tag'] = [t.tag for t in trades]

if strategy_instance is not None and hasattr(strategy_instance, "data1") and hasattr(strategy_instance, "data2"):
s1 = strategy_instance.data1.Close
s2 = strategy_instance.data2.Close
trades_df['PnL_cash'] = (
(trades_df['ExitPrice'] - trades_df['EntryPrice']) /
(s1.iloc[trades_df['EntryBar']].values + s2.iloc[trades_df['EntryBar']].values)
)
else:
trades_df['PnL_cash'] = np.nan

# Add indicator values
if len(trades_df) and strategy_instance:
for ind in strategy_instance._indicators:
Expand Down