Skip to content

Commit 6e9016c

Browse files
committed
PERF: df.itertuples over a subset of columns
1 parent 2a1f33c commit 6e9016c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

backtesting/_stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _round_timedelta(value, _period=_data_period(index)):
103103
s.loc['Duration'] = s.End - s.Start
104104

105105
have_position = np.repeat(0, len(index))
106-
for t in trades_df.itertuples(index=False):
106+
for t in trades_df[['EntryBar', 'ExitBar']].itertuples(index=False):
107107
have_position[t.EntryBar:t.ExitBar + 1] = 1
108108

109109
s.loc['Exposure Time [%]'] = have_position.mean() * 100 # In "n bars" time, not index time

0 commit comments

Comments
 (0)